fix: 引导流程结束后,再次访问引导页面自动跳转

This commit is contained in:
mofeng
2026-01-30 13:06:32 +08:00
parent b2b99115ec
commit f3b42e2aaf

View File

@@ -46,18 +46,32 @@ function t(key: string, params?: Record<string, unknown>): string {
router.beforeEach(async (to, _from, next) => {
const authStore = useAuthStore()
// Check if system needs setup
if (!authStore.initialized && to.name !== 'Setup') {
// Prevent access to setup after initialization
const shouldCheckSetup = to.name === 'Setup' || !authStore.initialized
if (shouldCheckSetup) {
try {
await authStore.checkSetupStatus()
if (authStore.needsSetup) {
return next({ name: 'Setup' })
}
} catch {
// Continue anyway
}
}
if (authStore.needsSetup) {
if (to.name !== 'Setup') {
return next({ name: 'Setup' })
}
} else if (authStore.initialized && to.name === 'Setup') {
if (!authStore.isAuthenticated) {
try {
await authStore.checkAuth()
} catch {
// Not authenticated
}
}
return next({ name: authStore.isAuthenticated ? 'Console' : 'Login' })
}
// Check authentication for protected routes
if (to.meta.requiresAuth !== false) {
if (!authStore.isAuthenticated) {