Browse Source

fix: 修复小程序退出登录后缓存未清空导致显示旧数据的问题

问题描述:
- 退出登录后重新登录,部分页面仍显示之前账号的旧数据
- 原因是只清除了 currentUser query,其他 React Query 缓存仍保留

修复方案:
- 退出登录时调用 queryClient.clear() 清空所有 React Query 缓存
- 两个小程序同时修复:mini (企业) 和 mini-talent (人才)

测试验证:
- 换账号登录后所有页面显示新账号数据
- 测试页面:首页、人才管理、数据统计、订单管理、设置

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 3 weeks ago
parent
commit
2aa6c2e5da
2 changed files with 5 additions and 6 deletions
  1. 3 3
      mini-talent/src/hooks/useAuth.tsx
  2. 2 3
      mini/src/hooks/useAuth.tsx

+ 3 - 3
mini-talent/src/hooks/useAuth.tsx

@@ -121,9 +121,9 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
       }
     },
     onSuccess: () => {
-      // 先清除用户状态
-      queryClient.setQueryData(['talentCurrentUser'], null)
-      // 立即跳转到登录页(不使用异步,因为 reLaunch 不返回 Promise)
+      // 清空所有 React Query 缓存,避免重新登录后显示旧数据
+      queryClient.clear()
+      // 立即跳转到登录页
       Taro.reLaunch({ url: '/pages/login/index' })
     },
     onError: (error) => {

+ 2 - 3
mini/src/hooks/useAuth.tsx

@@ -145,10 +145,9 @@ export const AuthProvider: React.FC<PropsWithChildren> = ({ children }) => {
       }
     },
     onSuccess: async () => {
-      // 先清除用户状态
-      queryClient.setQueryData(['currentUser'], null)
+      // 清空所有 React Query 缓存,避免重新登录后显示旧数据
+      queryClient.clear()
       // 使用 reLaunch 关闭所有页面并跳转到登录页
-      // 添加延迟确保状态更新完成
       await new Promise(resolve => setTimeout(resolve, 100))
       Taro.reLaunch({ url: '/pages/login/index' })
     },