fix(miniprogram): 退出登录后刷新仍保持登录态
根因:logout 清除 storage 期间并发请求触发 tryRefreshToken 写回新 token 修复:添加 isLoggingOut 标记,logout 时先标记阻止 token 刷新竞态
This commit is contained in:
@@ -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; });
|
||||
|
||||
Reference in New Issue
Block a user