From 5b26a355a07ed19e6718d8363bdbea1ca4ca19fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Wed, 6 May 2026 14:15:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(guards):=20=E4=BF=AE=E5=A4=8D=20SPA=20?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=AF=BC=E8=88=AA=E9=87=8D=E5=AE=9A=E5=90=91?= =?UTF-8?q?=E5=88=B0=E7=99=BB=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authLoader 中 initFromStorage() 后需重新调用 getState() 获取最新状态, 否则 isAuthenticated 检查使用过时的快照值导致已登录用户被重定向到登录页。 同步修复 usePermissionStore 的相同问题。 --- novalon-manage-web/src/router/guards.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/novalon-manage-web/src/router/guards.tsx b/novalon-manage-web/src/router/guards.tsx index 78894eb..8d3cc21 100644 --- a/novalon-manage-web/src/router/guards.tsx +++ b/novalon-manage-web/src/router/guards.tsx @@ -9,17 +9,18 @@ export async function authLoader() { return redirect('/login') } - const authState = useAuthStore.getState() + let authState = useAuthStore.getState() if (!authState.initialized) { authState.initFromStorage() + authState = useAuthStore.getState() } if (!authState.isAuthenticated) { return redirect('/login') } - const permState = usePermissionStore.getState() + let permState = usePermissionStore.getState() if (!permState.loaded) { const restored = permState.initFromStorage() @@ -27,10 +28,12 @@ export async function authLoader() { try { await permState.fetchUserMenus() } catch { + authState = useAuthStore.getState() authState.logout() return redirect('/login') } } + permState = usePermissionStore.getState() } return null