fix(web): 修复登录时序bug - token先存localStorage再取用户信息 (#734)
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled

This commit was merged in pull request #734.
This commit is contained in:
2026-07-22 22:42:09 +08:00
parent 3e48248c83
commit fcdf693707
Regular → Executable
+17 -1
View File
@@ -20,7 +20,14 @@ export const useLogin = () => {
const data = await mutation.mutateAsync(credentials)
const refreshToken = data.refresh_token ?? null
// 获取用户信息
// 先存 token 到 localStorage,确保后续请求拦截器能取到
// apiClient 拦截器从 localStorage 读 access_token
localStorage.setItem("access_token", data.access_token)
if (refreshToken) {
localStorage.setItem("refresh_token", refreshToken)
}
// 再获取用户信息(这时候请求带 Authorization header
const user = await authApi.getCurrentUser()
setAuth(user, data.access_token, refreshToken)
@@ -54,6 +61,15 @@ export const useWechatCallback = () => {
localStorage.removeItem("wechat_state")
const result = await mutation.mutateAsync({ code, state })
// 先存 token 到 localStorage,确保后续请求拦截器能取到
// apiClient 拦截器从 localStorage 读 access_token
localStorage.setItem("access_token", result.access_token)
if (result.refresh_token) {
localStorage.setItem("refresh_token", result.refresh_token)
}
// 再获取用户信息(这时候请求带 Authorization header
const user = await authApi.getCurrentUser()
setAuth(user, result.access_token, result.refresh_token)