回滚bug修复

This commit is contained in:
2026-04-14 14:11:06 +08:00
parent 0f88844e10
commit cda3c3345f
3 changed files with 56 additions and 10 deletions

View File

@@ -51,6 +51,22 @@ async function apiRequest(url, options = {}) {
if (response.status === 401) {
clearAuth();
// 防循环机制:检查是否已在登录页
if (window.location.pathname === '/index.php' || window.location.pathname === '/') {
console.warn('[Auth] 已在登录页收到401停止重定向');
return null;
}
// 防循环机制5秒内重复401则停止重定向
const now = Date.now();
const lastRedirect = parseInt(sessionStorage.getItem('_last_401_redirect') || '0');
if (now - lastRedirect < 5000) {
console.warn('[Auth] 5秒内重复401停止重定向。请检查Token是否有效。');
return null;
}
sessionStorage.setItem('_last_401_redirect', now.toString());
window.location.href = '/index.php';
return null;
}