fix(miniprogram): 退出登录后刷新仍保持登录态
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

根因:logout 清除 storage 期间并发请求触发 tryRefreshToken 写回新 token
修复:添加 isLoggingOut 标记,logout 时先标记阻止 token 刷新竞态
This commit is contained in:
iven
2026-05-10 10:36:17 +08:00
parent 11101ac204
commit 3c828bfc4a
2 changed files with 14 additions and 1 deletions

View File

@@ -30,8 +30,18 @@ async function getHeaders(): Promise<Record<string, string>> {
// --- Token refresh deduplication ---
let refreshPromise: Promise<boolean> | null = null;
let isLoggingOut = false;
export function markLoggingOut(): void {
isLoggingOut = true;
}
export function clearLoggingOut(): void {
isLoggingOut = false;
}
async function tryRefreshToken(): Promise<boolean> {
if (isLoggingOut) return false;
if (refreshPromise) return refreshPromise;
refreshPromise = doRefresh();
refreshPromise.finally(() => { refreshPromise = null; });