fix(login): 修复登录后跳转及认证拦截问题

- request.ts: 优化401处理,避免登录接口误判过期
- router/index.ts: 路由守卫增加用户信息获取
- stores/user.ts: fetchUserInfo增强错误处理,login前先清理旧状态
- Login.vue: 使用await router.push,避免重复报错
- user_service.py: bootstrap superuser密码同步
This commit is contained in:
hiderfong
2026-04-26 07:59:46 +08:00
parent 34466a1ae9
commit ad2f49de11
5 changed files with 100 additions and 26 deletions
+16 -2
View File
@@ -129,7 +129,7 @@ const router = createRouter({
routes,
})
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore()
// Public routes (login)
@@ -143,13 +143,27 @@ router.beforeEach((to, from, next) => {
next('/login')
return
}
if (!userStore.userInfo) {
try {
const userInfo = await userStore.fetchUserInfo()
if (!userInfo) {
userStore.logout()
next('/login')
return
}
} catch {
next('/login')
return
}
}
// Check role permissions
const allowedRoles = to.meta.roles as string[] | undefined
if (allowedRoles && allowedRoles.length > 0) {
const hasPermission = userStore.hasAnyRole(allowedRoles)
if (!hasPermission) {
next('/dashboard')
next(to.path === '/dashboard' ? '/login' : '/dashboard')
return
}
}