修复重定向导致无法续期

This commit is contained in:
mtvpls
2026-01-27 16:15:09 +08:00
parent 64bedb04b6
commit 258c95f6a2
4 changed files with 45 additions and 27 deletions
+3 -3
View File
@@ -89,9 +89,9 @@ export function TokenRefreshManager() {
const age = now - authInfo.timestamp;
const remaining = ACCESS_TOKEN_AGE - age;
// 剩余时间 < 10 分钟时需要刷新
// 剩余时间 < 10 分钟时需要刷新(包括已过期的情况)
const REFRESH_THRESHOLD = 10 * 60 * 1000; // 10 分钟
return remaining < REFRESH_THRESHOLD && remaining > 0;
return remaining < REFRESH_THRESHOLD;
};
// 保存原始 fetch
@@ -132,7 +132,7 @@ export function TokenRefreshManager() {
// 刷新成功,重试原请求(仅此一次)
response = await originalFetch(input, init);
// 如果重试后仍然是 401,说明有其他问题,不再重试
// 如果重试后仍然是 401,说明有问题,跳转登录
if (response.status === 401) {
console.error('[Token] Still 401 after refresh, redirecting to login');
window.location.href = `/login?redirect=${encodeURIComponent(window.location.pathname + window.location.search)}`;