修复跳转登录不登出
This commit is contained in:
@@ -111,3 +111,19 @@ export function getAuthInfoFromBrowserCookie(): AuthInfo | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 清除浏览器中的认证cookie (客户端使用)
|
||||
export function clearAuthCookie(): void {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 清除 auth cookie,设置过期时间为过去
|
||||
document.cookie = 'auth=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
|
||||
// 如果有其他域名或路径的cookie,也尝试清除
|
||||
document.cookie = 'auth=; path=/; domain=' + window.location.hostname + '; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
|
||||
} catch (error) {
|
||||
console.error('[Auth] Failed to clear cookie:', error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 如后续需要在客户端读取收藏等其它数据,可按同样方式在此文件中补充实现。
|
||||
*/
|
||||
|
||||
import { getAuthInfoFromBrowserCookie } from './auth';
|
||||
import { getAuthInfoFromBrowserCookie, clearAuthCookie } from './auth';
|
||||
import { DanmakuFilterConfig, EpisodeFilterConfig,SkipConfig } from './types';
|
||||
|
||||
// 全局错误触发函数
|
||||
@@ -561,6 +561,8 @@ async function fetchWithAuth(
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('注销请求失败:', error);
|
||||
// 登出失败时清除前端cookie
|
||||
clearAuthCookie();
|
||||
}
|
||||
const currentUrl = window.location.pathname + window.location.search;
|
||||
const loginUrl = new URL('/login', window.location.origin);
|
||||
|
||||
Reference in New Issue
Block a user