From eb7103e97ac0e29537ebaff4fb35728305f1038d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 28 Sep 2026 05:36:58 +0000 Subject: [PATCH] Fix sign-up/login not always redirecting to profile Two issues: - The login page had no error handling around the sign-in call, so any hiccup (slow connection, first page compile, etc.) failed silently: the button stayed stuck on "Logging in..." with no redirect and no error shown. - Both pages used a client-side router transition to move to /profile right after signing in, which can race with the session cookie landing in the browser. Switched to a full page navigation instead, which guarantees the cookie is present before /profile checks it. Verified with a 10-run automated stress test (5 signups + 5 logins, back to back with no delay) against a production build - all 10 now land on /profile reliably. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01VL5YUEf2B9LG4xdVUQwcSg --- src/app/login/page.tsx | 29 +++++++++++++++++------------ src/app/signup/page.tsx | 10 +++++----- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 7d269fa..32b4eb7 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -1,12 +1,10 @@ "use client"; import { useState, FormEvent } from "react"; -import { useRouter } from "next/navigation"; import { signIn } from "next-auth/react"; import Link from "next/link"; export default function LoginPage() { - const router = useRouter(); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); @@ -19,19 +17,26 @@ export default function LoginPage() { const email = String(form.get("email") ?? ""); const password = String(form.get("password") ?? ""); - const result = await signIn("credentials", { - redirect: false, - email, - password, - }); + try { + const result = await signIn("credentials", { + redirect: false, + email, + password, + }); - if (result?.error) { - setError("Incorrect email or password."); + if (!result || result.error) { + setError("Incorrect email or password."); + setLoading(false); + return; + } + + // A full page load (not a client-side transition) guarantees the + // browser has the fresh session cookie before /profile checks it. + window.location.href = "/profile"; + } catch { + setError("Something went wrong. Please try again."); setLoading(false); - return; } - - router.push("/profile"); } return ( diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx index f95d682..74e91fe 100644 --- a/src/app/signup/page.tsx +++ b/src/app/signup/page.tsx @@ -1,12 +1,10 @@ "use client"; import { useState, FormEvent } from "react"; -import { useRouter } from "next/navigation"; import { signIn } from "next-auth/react"; import Link from "next/link"; export default function SignupPage() { - const router = useRouter(); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); @@ -43,12 +41,14 @@ export default function SignupPage() { password: payload.password, }); - if (signInResult?.error) { - router.push("/login"); + if (!signInResult || signInResult.error) { + window.location.href = "/login"; return; } - router.push("/profile"); + // A full page load (not a client-side transition) guarantees the + // browser has the fresh session cookie before /profile checks it. + window.location.href = "/profile"; } catch { setError("Something went wrong. Please try again."); setLoading(false);