修复退出登录重定向问题和相关功能优化
- 修复DashboardLayout中的退出登录函数,确保清除所有认证信息 - 恢复_app.tsx中的认证逻辑,确保仪表盘页面需要登录访问 - 完善退出登录流程:清除本地存储 -> 调用登出API -> 重定向到登录页面 - 添加错误边界组件提升用户体验 - 优化React水合错误处理 - 添加JWT令牌验证API - 完善各个仪表盘页面的功能和样式
This commit is contained in:
@@ -60,11 +60,32 @@ export default function DashboardLayout({ children, title = '管理后台' }: Da
|
||||
setIsDemoMode(true);
|
||||
}, []);
|
||||
|
||||
const handleLogout = () => {
|
||||
// 清除本地存储并跳转到登录页
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user');
|
||||
router.push('/auth/login');
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
// 清除所有相关的本地存储
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('adminToken');
|
||||
localStorage.removeItem('user');
|
||||
|
||||
// 调用后端登出API(如果需要)
|
||||
try {
|
||||
await fetch('/api/auth/logout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
} catch (apiError) {
|
||||
console.log('API logout error (non-critical):', apiError);
|
||||
}
|
||||
|
||||
// 重定向到登录页面
|
||||
window.location.href = '/auth/login';
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
// 即使出错也要重定向到登录页面
|
||||
window.location.href = '/auth/login';
|
||||
}
|
||||
};
|
||||
|
||||
const toggleExpanded = (itemName: string) => {
|
||||
|
||||
Reference in New Issue
Block a user