From 9a6bb04bf51515d032fd6a2b86094ff1e309225c Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 13 Jun 2026 11:09:55 +0800 Subject: [PATCH] fix(frontend): distinguish initial authentication state on login page mount - Add wasUserPresentRef to detect if the user was already authenticated on initial page load. - Guard the useEffect redirect block so that it only redirects automatically if the user was already authenticated when mounting. - Prevent duplicate concurrent router.replace calls from canceling each other when logging in via the form. --- frontend/components/auth/login-page.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/components/auth/login-page.tsx b/frontend/components/auth/login-page.tsx index 807d7cb9..8ee38dc3 100644 --- a/frontend/components/auth/login-page.tsx +++ b/frontend/components/auth/login-page.tsx @@ -41,6 +41,7 @@ export function LoginPage() { const [loginSuccess, setLoginSuccess] = useState(false) const redirectedRef = useRef(false) const callbackProcessedRef = useRef(false) + const wasUserPresentRef = useRef(!!user) const resolveRedirectTarget = useCallback(() => { const callbackUrl = searchParams.get('callbackUrl') @@ -71,10 +72,12 @@ export function LoginPage() { } if (user) { - if (!redirectedRef.current) { - redirectedRef.current = true - router.replace(resolveRedirectTargetRef.current()) - setIsCheckingSession(false) + if (wasUserPresentRef.current) { + if (!redirectedRef.current) { + redirectedRef.current = true + router.replace(resolveRedirectTargetRef.current()) + setIsCheckingSession(false) + } } return }