Skip to content

Commit 009fa3f

Browse files
committed
fix: OAuth redirect loop — revert to server-side redirect, force secure cookie
Two issues: 1. Client-side HTML meta-refresh redirect (added for double-login fix) had broken JS syntax in template literal and was unreliable across browsers. Reverted to simple NextResponse.redirect(). 2. Cookie secure flag was conditional on NODE_ENV=production which may not be set on Amplify Lambda. Changed to always true (site is HTTPS-only).
1 parent 5da50e6 commit 009fa3f

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

app/api/auth/callback/google/route.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,11 @@ export async function GET(request: NextRequest) {
103103
const sessionToken = await createSessionForUser(user.id);
104104

105105
// ─── Set cookie & redirect ────────────────────────────────────
106-
// Use a client-side meta-refresh redirect so the browser fully
107-
// processes the Set-Cookie before navigating. Server-side 302/307
108-
// redirects from cross-origin OAuth flows can race with cookie storage.
109-
const destination = `${appUrl}/kid-dashboard`;
110-
const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=${destination}"><script>window.location.href="${destination}"</script></head><body>Signing in...</body></html>`;
111-
112-
const response = new NextResponse(html, {
113-
status: 200,
114-
headers: { "Content-Type": "text/html" },
115-
});
106+
const response = NextResponse.redirect(`${appUrl}/kid-dashboard`);
116107

117108
response.cookies.set(sessionCookieName, sessionToken, {
118109
httpOnly: true,
119-
secure: process.env.NODE_ENV === "production",
110+
secure: true,
120111
sameSite: "lax",
121112
maxAge: sessionMaxAgeSeconds,
122113
path: "/",

0 commit comments

Comments
 (0)