生产管理系统 - 拦截器业务逻辑增强

This commit is contained in:
2025-11-01 09:32:26 +08:00
parent a1b3335664
commit e99567e6b3
6 changed files with 185 additions and 56 deletions

View File

@@ -65,6 +65,11 @@ export function AuthProvider({ children }: AuthProviderProps) {
localStorage.removeItem('user');
removeTokenCookie(); // 清除 cookie
setLoading(false);
// 跳转到登录页
if (typeof window !== 'undefined') {
window.location.href = '/login';
}
};
// 验证当前用户信息
@@ -89,9 +94,9 @@ export function AuthProvider({ children }: AuthProviderProps) {
// 更新用户信息(可能包含最新的权限、角色等)
setUser({
...userData,
...response.data.data, // 合并最新的用户信息
...response.data, // 合并最新的用户信息
});
console.log('✅ 用户验证成功,最新用户信息:', response.data.data);
console.log('✅ 用户验证成功,最新用户信息:', response.data);
} else {
// Token无效清除用户信息
console.warn('⚠️ Token验证失败清除用户信息');

View File

@@ -20,8 +20,8 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps)
const currentPath = window.location.pathname;
// 如果已经在登录页面,不需要重定向
if (currentPath === '/login' || currentPath === '/register') {
// 如果已经在认证页面(包括 /login 开头的所有路径),不需要重定向
if (currentPath.startsWith('/login')) {
console.log(`📄 已在认证页面,跳过拦截: ${currentPath}`);
return;
}
@@ -53,8 +53,8 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps)
);
}
// 如果在认证页面(登录/注册),直接渲染子组件,不需要认证检查
if (currentPath === '/login' || currentPath === '/register') {
// 如果在认证页面(包括 /login 开头的所有路径),直接渲染子组件,不需要认证检查
if (currentPath.startsWith('/login')) {
return <>{children}</>;
}