From 00da22e5946826c7919d416ca9d111ddd38f23bb Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sun, 14 Jun 2026 02:20:20 +0800 Subject: [PATCH] Fix auth login redirect loop --- frontend/components/auth/LoginClient.tsx | 14 ---------- .../auth/__tests__/loginRedirectLoop.test.ts | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 frontend/components/auth/__tests__/loginRedirectLoop.test.ts diff --git a/frontend/components/auth/LoginClient.tsx b/frontend/components/auth/LoginClient.tsx index eb8d8020..a8e71dca 100644 --- a/frontend/components/auth/LoginClient.tsx +++ b/frontend/components/auth/LoginClient.tsx @@ -169,20 +169,6 @@ export function LoginClient({ nextPath, initialError, initialMode }: LoginClient } }; - useEffect(() => { - if (!supabaseReady) return; - const run = async () => { - const supabase = getSupabaseBrowserClient(); - const { - data: { session }, - } = await supabase.auth.getSession(); - if (session?.user) { - router.replace(nextPath); - } - }; - void run(); - }, [nextPath, router, supabaseReady]); - const onGoogleSignIn = async () => { setErrorText(""); setInfoText(""); diff --git a/frontend/components/auth/__tests__/loginRedirectLoop.test.ts b/frontend/components/auth/__tests__/loginRedirectLoop.test.ts new file mode 100644 index 00000000..a2035759 --- /dev/null +++ b/frontend/components/auth/__tests__/loginRedirectLoop.test.ts @@ -0,0 +1,28 @@ +import fs from "node:fs"; +import path from "node:path"; + +function assert(condition: unknown, message: string) { + if (!condition) throw new Error(message); +} + +export function runTests() { + const source = fs.readFileSync( + path.join(process.cwd(), "components", "auth", "LoginClient.tsx"), + "utf8", + ).replace(/\r\n/g, "\n"); + + const start = source.indexOf("const onResetPassword"); + const end = source.indexOf("const onGoogleSignIn"); + + assert( + start >= 0 && end > start, + "login page pre-submit auth initialization block must be detectable by this regression test", + ); + + const loginMountEffect = source.slice(start, end); + + assert( + !loginMountEffect.includes("router.replace(nextPath)"), + "login page must not auto-return to nextPath from a cached Supabase session before the user submits auth", + ); +}