life-script启动后地址栏无限重复切换bug修复

This commit is contained in:
2025-12-24 11:38:48 +08:00
parent 7049cd614a
commit 1aa39e11b4
5 changed files with 122 additions and 165 deletions
+8 -2
View File
@@ -55,10 +55,16 @@ api.interceptors.response.use(
if (error.response) {
const { status, data } = error.response;
if (status === 401) {
// token 过期,清除登录状态
// token 过期或无效,清除所有登录相关状态
localStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
window.location.href = '/';
localStorage.removeItem('life_trajectory_v3'); // 清除 Zustand 持久化状态
// 避免重复跳转导致的无限循环
if (window.location.pathname !== '/') {
window.location.href = '/';
}
return Promise.reject(new Error('未授权访问,请重新登录'));
}
return Promise.reject(new Error(data?.message || `请求失败: ${status}`));
}