Browse Source

fix: 修复人才小程序和企业小程序退出登录后 localStorage 未清除 token 的 bug

问题分析:
- 人才小程序 useAuth 存储的 key 是 talent_token/talent_user,但 SettingsPage 清除的是 token/user
- 企业小程序 useAuth 存储的 key 是 enterprise_token/enterpriseUserInfo,但 Settings 清除的是 enterpriseToken/enterpriseUser

修复内容:
- rencai-settings-ui: 修正 localStorage key 为 talent_token 和 talent_user
- yongren-settings-ui: 修正 localStorage key 为 enterprise_token 和 enterpriseUserInfo

Co-Authored-By: Claude <noreply@anthropic.com>
yourname 5 days ago
parent
commit
29a10bc0a0

+ 4 - 5
mini-ui-packages/rencai-settings-ui/src/pages/SettingsPage/SettingsPage.tsx

@@ -141,9 +141,9 @@ const SettingsPage: React.FC = () => {
         throw new Error('退出登录失败')
       }
 
-      // 清除本地存储
-      Taro.removeStorageSync('token')
-      Taro.removeStorageSync('user')
+      // 清除本地存储(使用与 useAuth 一致的 key)
+      Taro.removeStorageSync('talent_token')
+      Taro.removeStorageSync('talent_user')
 
       // 跳转到登录页
       Taro.reLaunch({ url: '/pages/login/index' })
@@ -152,8 +152,7 @@ const SettingsPage: React.FC = () => {
         title: '已退出登录',
         icon: 'success'
       })
-    } catch (error) {
-      console.error('退出登录失败:', error)
+    } catch (_error) {
       Taro.showToast({
         title: '退出登录失败',
         icon: 'none'

+ 5 - 6
mini-ui-packages/yongren-settings-ui/src/pages/Settings/Settings.tsx

@@ -5,7 +5,6 @@ import { useQuery } from '@tanstack/react-query'
 import { YongrenTabBarLayout } from '@d8d/yongren-shared-ui/components/YongrenTabBarLayout'
 import { Navbar } from '@d8d/mini-shared-ui-components/components/navbar'
 import { useAuth } from '@d8d/mini-enterprise-auth-ui/hooks'
-import type { User } from '@d8d/mini-enterprise-auth-ui/hooks'
 import { enterpriseCompanyClient } from '../../api/companyClient'
 
 // 延期功能列表(因史诗012系统设置API延期)
@@ -18,7 +17,7 @@ const Settings: React.FC = () => {
   const { data: companyOverview, isLoading } = useQuery({
     queryKey: ['company-overview'],
     queryFn: async () => {
-      const res = await enterpriseCompanyClient.overview.$get({} as any)
+      const res = await enterpriseCompanyClient.overview.$get({} as never)
       if (!res.ok) {
         throw new Error('获取企业信息失败')
       }
@@ -64,9 +63,9 @@ const Settings: React.FC = () => {
       content: '确定要退出登录吗?',
       success: (res) => {
         if (res.confirm) {
-          // 清除本地存储的认证信息
-          Taro.removeStorageSync('enterpriseToken')
-          Taro.removeStorageSync('enterpriseUser')
+          // 清除本地存储的认证信息(使用与 useAuth 一致的 key)
+          Taro.removeStorageSync('enterprise_token')
+          Taro.removeStorageSync('enterpriseUserInfo')
 
           // 跳转到登录页
           Taro.reLaunch({
@@ -102,7 +101,7 @@ const Settings: React.FC = () => {
     )
   }
 
-  const companyData: any = companyOverview || {}
+  const companyData: Record<string, unknown> = companyOverview || {}
 
   return (
     <YongrenTabBarLayout activeKey="settings">