#missmatch
14 messages · Page 1 of 1 (latest)
This error is coming from Better Auth, not from Convex Auth itself, and the provided knowledge only touches Better Auth–Convex integration at a high level. There’s no explicit mention of a state_mismatch error in the sources, so I can’t give a definitive, step‑by‑step fix; I can only point to likely misconfiguration areas.
From the logs:
location: '<https://be-ntc.com/api/auth/error?error=state_mismatch'>
Better Auth is redirecting to your app with error=state_mismatch during the Google callback at:
GET /api/auth/callback/google on your Convex deployment.
Based on the available docs and Discord threads, the most relevant things to double‑check are:
-
Callback URL and base URL alignment
For Convex + OAuth, the provider’s callback must point at your Convex HTTP Actions URL (the
.siteURL), with the correct path, e.g.:<https://<your-deployment>.convex.site/api/auth/callback/google>This must exactly match what you configured in the Google console. [Google OAuth; General OAuth]
Also ensure you’re not accidentally mixing
.cloudand.siteURLs; Better Auth routes must be hit via the.siteURL when exposed through Convex HTTP actions. [Better Auth 404] -
SITE_URL / CUSTOM_AUTH_SITE_URL / Better Auth baseURL consistency
- Convex Auth expects
SITE_URL(and optionallyCUSTOM_AUTH_SITE_URL) to be set correctly for your environment. [OAuth production; Custom callback URLs]- Better Auth also has its own
baseURLoption; in a Convex integration, that should be consistent with where the browser is actually starting the OAuth flow and where the callback returns. - A mismatch between where the flow starts (e.g.
<https://be-ntc.com/...>) and where the callback is handled (<https://<deployment>.convex.site/...>) can causestateverification to fail.
- Better Auth also has its own
-
Environment separation (dev vs prod)
If you have separate Google OAuth “apps” for dev and prod (recommended), make sure:
- The Google client ID/secret you set in Convex env vars (
AUTH_GOOGLE_ID,AUTH_GOOGLE_SECRET) belong to the same Google project whose callback URL you configured. [Google OAuth; OAuth production]
- The Google client ID/secret you set in Convex env vars (
-
Routing through your own domain
Your error redirect is going to
<https://be-ntc.com/api/auth/error...,> which suggests you may be proxying or rewriting between your domain and Convex. The Better Auth + Convex 404 thread shows that mis‑routing between.cloudand.sitecan break things; a similar mis‑routing could also break thestatecookie or parameter handling. [Better Auth 404]
Because the sources don’t include Better Auth’s internal state_mismatch docs or a concrete example of this exact error, I can’t say more precisely what in your setup is wrong. If you share:
- Your Google OAuth callback URL as configured in Google,
- The Convex HTTP actions URL,
- How you set
baseURLin Better Auth and anySITE_URL/CUSTOM_AUTH_SITE_URLin Convex,
then the next step would be to verify that all four are consistent and that the browser always stays on a single origin for the start and end of the OAuth flow.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@iron citrus Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@west shadow '2026-01-12T09:10:34.731Z ERROR [Better Auth]: APIError' { [APIError] status: 'FOUND', body: undefined, headers: Headers { 'set-cookie': '__Secure-better-auth.session_token=cQCGkBcuTYAO19MiJpNN6Wffv2QmyYMi.ddRYjJPQVxYzJinHLPiOG4Jy6LMWLYXLJOdO%2B6nUr6g%3D; Max-Age=604800; Path=/; HttpOnly; Secure; SameSite=Lax', location: 'bentc:///' }, statusCode: 302, name: 'APIError' }
Let me check the knowledge base for you again. One moment! :books:
This log line is just Better Auth reporting a successful redirect, not an error in the OAuth flow itself.
From the APIError object:
status: 'FOUND',statusCode: 302– this is an HTTP 302 redirect.headers.location: 'bentc:///'– Better Auth is redirecting the browser to your custom schemebentc:///.set-cookie: __Secure-better-auth.session_token=...– a Better Auth session cookie is being set.
In Convex + Better Auth, redirects after sign‑in are controlled by:
- The
SITE_URL/CUSTOM_AUTH_SITE_URLand theredirectcallback in Convex Auth. [ConvexAuthConfig; Custom callback URLs] - The
redirectToyou pass tosignIn(...)on the client. [OAuth config]
For React Native / mobile, the recommended pattern is to allow absolute redirect URIs (like myapp://...) via a custom redirect callback, and then pass the full URI from the client. [SITE_URL mobile]
So, seeing location: 'bentc:///' means:
- Your
redirectcallback (or default behavior plusredirectTo) is returningbentc:///. - Better Auth is issuing a 302 to that URI and setting the session cookie on the Convex domain.
If this is not the redirect you want, check:
- What
redirectToyou pass intosignIn("google", { redirectTo }). - Your
redirectcallback in the Convex Auth / Better Auth config, and ensure it returns the correct URL(s) you intend to support. [ConvexAuthConfig; SITE_URL mobile]
The knowledge sources don’t include Better Auth’s internal error handling, but nothing here indicates a failed login—only that Better Auth is redirecting to bentc:/// with a session cookie set.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@iron citrus Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@west shadow 1/12/2026, 10:30:38 AM [CONVEX H(GET /api/auth/callback/google)] [ERROR] '2026-01-12T09:30:38.829Z ERROR [Better Auth]: APIError' { [APIError] status: 'FOUND', body: undefined, headers: Headers { 'set-cookie': 'better-auth.session_token=tiCHrYFfaTMDfjDET0nCSecjuCsd0UyX.YH%2BuEpslmyLuPx7ux7jFf1qoAbQFxY3C9V2iGIcY7G4%3D; Max-Age=604800; Path=/; HttpOnly; SameSite=Lax', location: 'bentc:///' }, statusCode: 302, name: 'APIError' }
Let me check the knowledge base for you again. One moment! :books:
This log line indicates that the Google OAuth callback reached your Convex HTTP action and Better Auth completed the flow, then issued a redirect — it is not a failed OAuth exchange by itself.
From the entry:
status: 'FOUND', statusCode: 302→ HTTP 302 redirect.headers.location: 'bentc:///'→ Better Auth is redirecting to your custom schemebentc:///.set-cookie: better-auth.session_token=...; Max-Age=604800; Path=/; HttpOnly; SameSite=Lax→ a Better Auth session cookie was set on the Convex domain.
This matches the expected pattern for social sign‑in with Convex + Better Auth, where:
- The OAuth provider callback hits your Convex .site URL, e.g.
<https://<deployment>.convex.site/api/auth/callback/google.> [Google OAuth; General OAuth] - Better Auth then sets its session cookie and redirects to whatever URL you’ve configured (here:
bentc:///), typically viaredirectToand/or aredirectcallback. [ConvexAuthConfig; SITE_URL mobile thread]
So:
- If your app is not opening on
bentc:///, the issue is likely on the client side (deep‑link / scheme handling), not in Convex/Better Auth. - If
bentc:///is not the URL you intend, check:- What you pass as
redirectTowhen callingsignIn("google", { redirectTo }). - Any custom
redirectcallback in your Convex Auth / Better Auth config, and ensure it returns the correct URL(s). [ConvexAuthConfig]
- What you pass as