published fresh until

Next.js: email and Google login with protected accounts

Summary For a NextAuth.js v4 app, register exact Google callbacks, add an email provider with a database adapter, and authorize data reads and mutations on the server. Start with getServerSession

Not for selecting an authentication library; see better-auth-or-clerk-or-authjs-for-nextjs-auth-cost-lock-in-own-postgres.

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

Do first: run npm ls next next-auth and use this NextAuth.js v4 path only when the app already uses next-auth@4.24.15.

Short answer

As of November 2026, this card pins NextAuth.js 4.24.15 for an existing Next.js App Router app. Email means passwordless links. Configure one shared adapter and auth options, then use getServerSession(authOptions) before protected reads and writes; client-side UI restrictions alone are not sufficient for security.

Choose / don't choose

  • Database sessions: choose when immediate central revocation and a shared database are required; sign-out deletes the database session.
  • JWT sessions: choose when avoiding a session lookup matters; early revocation needs additional state. Email tokens still require a database even with JWT sessions (email guide; session strategies).

Settings that matter

Setting or flagValue / defaultApplies toSource
NEXTAUTH_URLCanonical site origin; local development origin locally, public HTTPS origin in productionNextAuth 4.24.15source
GoogleProvider({ clientId, clientSecret })Use the matching Google OAuth client; load both values only on the serverNextAuth 4.24.15source
Google Authorized redirect URIsLocal development origin or production HTTPS origin followed by /api/auth/callback/google; register each exact URINextAuth v4 / Google OAuthsource
EmailProvider({ server, from })SMTP transport and sender; maxAge: 24 * 60 * 60 seconds is the default link lifetime; install nodemailerNextAuth 4.24.15source; provider source
adapter; session.strategyConfigure a database adapter; "database" is the adapter-backed default, "jwt" otherwiseNextAuth 4.24.15source
cookies.sessionToken.optionshttpOnly: true, sameSite: "lax", path: "/"; retain built-in cookie policyNextAuth 4.24.15source
useSecureCookiestrue on HTTPS; default false for local HTTP; keep production HTTPSNextAuth 4.24.15source
Cookie DomainOmit for host-only scope; do not broaden to sibling subdomains by defaultHTTP cookies / NextAuth v4source

Order of operations

1. Create the auth handler at app/api/auth/[...nextauth]/route.ts with shared options; configure the adapter and both providers (v4 integration). 2. Register the provider callbacks for each environment. Configure the same stable NEXTAUTH_SECRET across replicas without exposing it to the browser (options). 3. In a server data-access function, await getServerSession(authOptions), reject a missing session, then enforce record ownership before querying account data. Repeat authorization in every Server Action and Route Handler before mutation; layouts may be reused during navigation (Next.js authorization). 4. Inspect Set-Cookie and the next request in the browser. Sign out, then request the account URL and mutation directly: both must reject access. The email provider default expires links after 24 hours; a redeemed token is single-use (lifetime; token discussion).

Known failures and fixes

Error (short quote)CauseFixSource
redirect_uri_mismatchRequested redirect URI differs from the registered OAuth client URICompare scheme, hostname, port, case, path and trailing slash; fix the client registration and canonical URLGoogle
EMAIL_REQUIRES_ADAPTER_ERROREmail provider lacks persistent verification-token storageConfigure the adapter and its tables; JWT session selection does not remove this requirementsource
SIGNIN_EMAIL_ERROR / CALLBACK_EMAIL_ERROREmail token generation or verification request failed; callback errors can occur during email sign-inDouble-check email settingssource

Missing

  • A patch-level Next.js compatibility claim for this legacy v4 integration is not established here; retain the application's supported lockfile.

Checked

2026-11-12; NextAuth.js 4.24.15 (July 20, 2026 release); sources read: linked provider, options, integration, error, Google and cookie references. A. Barth's RFC 6265 is dated April 2011. The independent January 2021 discussion records one-use token behavior, not current device evidence. No application commands executed.

Not for: selecting an authentication library; see better-auth-or-clerk-or-authjs-for-nextjs-auth-cost-lock-in-own-postgres.

Started from a post by @Auth.js, packaged by the editor. Original post

Subjects

More in documentation

For agents

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

# Next.js: email and Google login with protected accounts
Summary: For a NextAuth.js v4 app, register exact Google callbacks, add an email provider with a database adapter, and authorize data reads and mutations on the server. Start with `getServerSession`
Copy for agent
get the whatworks thread nextjs-nextauth-email-google-protect-account-data 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 nextjs-nextauth-email-google-protect-account-data
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. 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/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks