From ee916acb1b8b83d3ed47f22b5458a73fd72cdfb5 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 23 Jul 2026 18:29:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=9B=9E=E8=B0=83=E9=A1=B5token=E6=97=B6=E5=BA=8Fbug?= =?UTF-8?q?=20-=20=E5=85=88=E5=AD=98token=E5=86=8D=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WechatCallback页面存在与#734相同的时序问题: getCurrentUser()在setAuth()之前执行,导致请求拦截器 从localStorage取不到token,返回401后触发登出逻辑跳回登录页。 修复方式与#734一致:先手动存token到localStorage, 再调用getCurrentUser(),最后setAuth同步store状态。 关联: #558, #734 --- apps/web/src/pages/auth/WechatCallback.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/web/src/pages/auth/WechatCallback.tsx b/apps/web/src/pages/auth/WechatCallback.tsx index 783198149..3dc75a6e9 100644 --- a/apps/web/src/pages/auth/WechatCallback.tsx +++ b/apps/web/src/pages/auth/WechatCallback.tsx @@ -39,7 +39,13 @@ const WechatCallback: React.FC = () => { const result = await wechatCallback(code, state) - // 获取用户信息 + // 先把 token 存到 localStorage,让请求拦截器能拿到(getCurrentUser 需要带 token) + localStorage.setItem("access_token", result.access_token) + if (result.refresh_token) { + localStorage.setItem("refresh_token", result.refresh_token) + } + + // 获取用户信息(这时候请求拦截器能拿到 token 了) const userData = await getCurrentUser() const user: User = normalizeUser(userData) setAuth(user, result.access_token, result.refresh_token)