published fresh until

How do I let users sign in with Google or an email link and stay logged in?

Summary When adding Google or magic-link login to a Next.js app, cover production redirects, scanner-opened links, session and logout behavior, and optional second factor. Account deletion and data removal remain open questions with no tested answer.

Not for collecting emails before launch, see case-waitlist-nextjs-email-capture-spam-protection-confirmation-email; who can see what, see case-admin-panel-roles-nextjs-supabase-who-can-see-what; profile page, see case-profile-settings-form-validation-avatar-upload

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The case

You want people to sign in with Google or an emailed link, stay signed in, and sign out cleanly. Success looks like: login that works in production and not only on localhost, links that do not expire when a mail scanner opens them, a clear session choice, and optional second factor. Stack: Next.js with Better Auth or Supabase Auth.

This is a map, not new advice: every row points to an existing WhatWorks thread. Nobody here ran this whole build; the Status column says what each linked thread rests on. "Tried" would need a linked trial report, and none of the linked threads has one yet.

Parts, in the order people do them

PartWhat to useStatusLink
Start without hand-rolled authLibrary skill that plans the setup from your framework and ORMDocumented: vendor or primary source, not tried (no linked trial)How do I add login to my app without the agent hand-rolling auth?
Google login fails liveExact redirect address registered in the consoleDocumented: vendor or primary source, not tried (no linked trial)Google login works locally but fails with redirect_uri_mismatch live
State error after redirectStart and finish the flow on the same domainDocumented: vendor or primary source, not tried (no linked trial)Social login fails with state_mismatch or state_not_found: why?
Email link says expiredMail scanners open the one-time link firstDocumented: vendor or primary source, not tried (no linked trial)Users click my magic link and get 'invalid or expired': why?
Email link opens localhostSet the site address for confirmation mailsDocumented: vendor or primary source, not tried (no linked trial)Why does my Supabase signup email link open localhost in production?
Sessions and logoutToken cookie or database sessionDocumented: vendor or primary source, not tried (no linked trial)JWT or database session for my app, and how does logout work?
Second factorAuthenticator app with backup codesDocumented: vendor or primary source, not tried (no linked trial)How do I add authenticator-app 2FA to my login?
Delete my account flowNo tested answer yetNo tested answer yetnone (see open request)

Where it breaks

Open questions

  • Parts marked "No tested answer yet" are gaps in WhatWorks; ask for them with the request tool so an editor can look: account deletion and data removal.

Sources

Each linked WhatWorks thread cites its own primary sources; this page adds none of its own. Status labels checked 2026-11-15 against the linked thread pages.

As of October 2026. who can see what, see case-admin-panel-roles-nextjs-supabase-who-can-see-what; a profile page, see case-profile-settings-form-validation-avatar-upload.

Started from a post by @WhatWorks editors, packaged by the editor.

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I let users sign in with Google or an email link and stay logged in?
Summary: When adding Google or magic-link login to a Next.js app, cover production redirects, scanner-opened links, session and logout behavior, and optional second factor. Account deletion and data removal remain open questions with no tested answer.
Copy for agent
get the whatworks thread case-login-google-magic-link-sessions-logout-nextjs-better-auth-supabase and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread case-login-google-magic-link-sessions-logout-nextjs-better-auth-supabase
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp