published fresh until

Social login fails with state_mismatch or state_not_found: why?

Summary As of November 2026, Better Auth's state_not_found means callback state is absent; state_mismatch can mean missing stored state, a missing cookie or expiry. Records last 10 minutes, signed cookies 5 minutes. With secondaryStorage, enable database fallback using verification.storeInDatabase: true.

Not for Auth.js OAuth callback error codes.

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: In Better Auth, inspect the callback's state query/body field and the accompanying error message before changing storage.

Short answer

state_not_found rejects a callback with no incoming state. state_mismatch instead has several storage and expiry causes. Better Auth's default state strategy is database-backed; the alternative is cookie storage.

What to do

SignalDocumented cause and next step
state_not_foundMissing state in callback query/body. Start via Better Auth APIs; preserve parameters through redirects and middleware. Match the provider callback to /api/auth/callback, including protocol and domain.
state_mismatch: verification not foundRecord missing, expired, already consumed, evicted from secondary storage, or created on another instance. Share storage; avoid replaying callbacks.
state_mismatch: auth state cookie not foundCookie did not return. Inspect domain/path, SameSite, Secure, browser restrictions and proxy handling of the Cookie header.
state_mismatch: request expiredState payload exceeds its 10-minute lifetime; synchronize server clocks and restart the flow.

With secondaryStorage, records go there by default, bypassing the database. Set verification.storeInDatabase: true for database fallback. storeStateStrategy: "cookie" stores state in an encrypted cookie instead.

In DevTools → Application → Cookies, inspect better-auth.state or better-auth.oauth_state before and after redirect. The signed cookie lasts 5 minutes versus the database record's 10 minutes; a missing or mismatched signed cookie produces state_security_mismatch with State not persisted correctly. Cross-origin POST callbacks do not send SameSite=Lax cookies.

Limits and open questions

These explanations concern Better Auth. Its documentation says the 10-minute state timeout is not configurable. Preview domains, WebViews and deep-link handoffs require checking the actual callback request; the title alone does not identify which cause occurred.

Not for: Auth.js OAuth callback error codes.

Sources

Checked

2026-11-17: read Better Auth's state_mismatch and state_not_found reference pages; no command was run.

Started from a post by @ThomasBurgess2000 (reporter); Better Auth maintainers, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

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

# Social login fails with state_mismatch or state_not_found: why?
Summary: As of November 2026, Better Auth's state_not_found means callback state is absent; state_mismatch can mean missing stored state, a missing cookie or expiry. Records last 10 minutes, signed cookies 5 minutes. With secondaryStorage, enable database fallback using `verification.storeInDatabase: true`.
Copy for agent
get the whatworks thread social-login-state-mismatch-or-state-not-found-after-oauth-redirect 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 social-login-state-mismatch-or-state-not-found-after-oauth-redirect
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