From 3c8a9f74f8901b6d4c33d6274e3a7a1670f9f12c Mon Sep 17 00:00:00 2001 From: Autumn-27 <53844290+Autumn-27@users.noreply.github.com> Date: Fri, 7 Aug 2026 09:43:30 -0400 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E5=AE=88=E5=8D=AB=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E7=99=BB=E5=BD=95=E9=A1=B5=E5=89=8D=E6=B8=85=E9=99=A4?= =?UTF-8?q?=20cookie=EF=BC=8C=E4=BF=AE=E5=A4=8D=20cookie=20=E4=B8=8E=20loc?= =?UTF-8?q?alStorage=20=E4=B8=8D=E4=B8=80=E8=87=B4=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E6=97=A0=E9=99=90=E9=87=8D=E5=AE=9A=E5=90=91=E7=99=BD?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (main)/layout.tsx 的客户端守卫判定未登录时只跳 /login,未清 cookie; 而 proxy.ts 仅凭 cookie 是否存在放行,二者在 cookie 存在但 localStorage 为空时互相弹跳 → 无限重定向 → 白屏。跳转前调用 auth.clearToken() 同步 清除两处凭证,与退出登录/401 处理的既有约定保持一致。 Co-Authored-By: Claude Opus 4.8 --- web/src/app/(main)/layout.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/src/app/(main)/layout.tsx b/web/src/app/(main)/layout.tsx index fef8c20..1022dfc 100644 --- a/web/src/app/(main)/layout.tsx +++ b/web/src/app/(main)/layout.tsx @@ -37,6 +37,10 @@ export default function Layout({ children }: Readonly<{ children: ReactNode }>) if (auth.getToken()) { setAuthed(true); } else { + // 客户端守卫认为未登录时,必须同时清掉 cookie:否则 proxy.ts 仅凭 + // “cookie 存在”就把我们从 /login 又重定向回主界面,与本守卫来回弹跳 + // 形成无限重定向 → 白屏(cookie 与 localStorage 不一致时触发)。 + auth.clearToken(); window.location.href = "/login"; } }, []);