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
| Signal | Documented cause and next step |
|---|---|
state_not_found | Missing 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 found | Record missing, expired, already consumed, evicted from secondary storage, or created on another instance. Share storage; avoid replaying callbacks. |
state_mismatch: auth state cookie not found | Cookie did not return. Inspect domain/path, SameSite, Secure, browser restrictions and proxy handling of the Cookie header. |
state_mismatch: request expired | State 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