From f3b42e2aaffeb233a2d82f0c7315ba0ad4661f0e Mon Sep 17 00:00:00 2001 From: mofeng Date: Fri, 30 Jan 2026 13:06:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=95=E5=AF=BC=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E5=90=8E=EF=BC=8C=E5=86=8D=E6=AC=A1=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E5=BC=95=E5=AF=BC=E9=A1=B5=E9=9D=A2=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/router/index.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/web/src/router/index.ts b/web/src/router/index.ts index 2f617e4e..30c72d3c 100644 --- a/web/src/router/index.ts +++ b/web/src/router/index.ts @@ -46,18 +46,32 @@ function t(key: string, params?: Record): 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) {