docs/content/docs/reference/errors/state_not_found.mdx
During the OAuth callback, Better Auth expects a state value to be present on the incoming request.
This state is originally generated when the OAuth flow starts and is sent to the provider. When the
provider redirects back to your app, it should include the same state value in the callback request.
If the state is missing entirely in the callback request (query or body),
we cannot validate the flow and the request is rejected.
This check prevents CSRF and replay attacks by ensuring the callback belongs to the same browser session that initiated the flow.
/api/auth/callback without starting an OAuth flow first.state on the authorize request (custom/manual flow overriding parameters).Always initiate OAuth through Better Auth so we can generate and send state correctly. Avoid manually hitting
callback endpoints or constructing authorize URLs unless you fully mirror Better Auth's parameters.
/api/auth/callback route (including
protocol and domain).state).Use your browser DevTools → Network to inspect the callback request:
?state=... (or that the request body contains state if you expect one).state cookie exists prior to
the redirect back.