回滚bug修复
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user