From 70e5a232c9a591ec143f1a9558394fe8e51c9642 Mon Sep 17 00:00:00 2001 From: Barcode Betty Date: Sun, 19 Apr 2026 15:22:37 +0000 Subject: [PATCH] fix: resolve sign-in redirect race condition in Login.tsx Use window.location.href = '/' instead of React Router navigate() after successful sign-in. Better-Auth's useSession() hasn't updated its internal cache when navigate() fires, causing ProtectedRoute to see a null session and redirect back to /login. A full page reload reinitializes useSession() with fresh cookie-backed session state. Co-Authored-By: Paperclip --- src/pages/Login.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index ae7fc0c..23d3825 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -31,11 +31,12 @@ export function Login() { throw new Error(authError.message ?? 'Sign in failed') } - // After successful signIn, force a session fetch to confirm the cookie is set - // before navigating to the protected route + // After successful signIn, force a full page reload so Better-Auth's + // useSession() reinitializes with fresh cookie-backed session state. + // Using React Router's navigate() races with Better-Auth's internal update. const sessionResult = await authClient.getSession() if (sessionResult.data) { - navigate('/') + window.location.href = '/' } else { setError('Sign in failed. Please try again.') }