mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-02 19:11:54 +08:00
fix: 引导流程结束后,再次访问引导页面自动跳转
This commit is contained in:
@@ -46,18 +46,32 @@ function t(key: string, params?: Record<string, unknown>): string {
|
|||||||
router.beforeEach(async (to, _from, next) => {
|
router.beforeEach(async (to, _from, next) => {
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
// Check if system needs setup
|
// Prevent access to setup after initialization
|
||||||
if (!authStore.initialized && to.name !== 'Setup') {
|
const shouldCheckSetup = to.name === 'Setup' || !authStore.initialized
|
||||||
|
if (shouldCheckSetup) {
|
||||||
try {
|
try {
|
||||||
await authStore.checkSetupStatus()
|
await authStore.checkSetupStatus()
|
||||||
if (authStore.needsSetup) {
|
|
||||||
return next({ name: 'Setup' })
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
// Continue anyway
|
// 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
|
// Check authentication for protected routes
|
||||||
if (to.meta.requiresAuth !== false) {
|
if (to.meta.requiresAuth !== false) {
|
||||||
if (!authStore.isAuthenticated) {
|
if (!authStore.isAuthenticated) {
|
||||||
|
|||||||
Reference in New Issue
Block a user