Guide
bad_oauth_state
How this guide was made: Written with AI assistance and checked against the sources linked on this page.
Updated
Short answer: bad_oauth_state means Supabase received an OAuth state value it cannot use. The state is malformed, not on record, or expired. Start the sign-in again from your app, make sure the provider and your Redirect URLs point to Supabase, and finish the sign-in in the same browser where you started it.
What does bad_oauth_state mean?
The error code is bad_oauth_state. Supabase's error page describes it as: "OAuth state (data echoed back by the OAuth provider to Supabase Auth) is not in the correct format." (Supabase: Auth error codes). So the state is a value that Supabase sends out when sign-in starts and that the provider returns at the callback.
The Auth server returns this code in three checks on the state. The messages are "OAuth state parameter is invalid" when the state is not a valid ID, "OAuth state not found or expired" when no record matches, and "OAuth state has expired" when the record is too old (supabase/auth: external.go). A callback with no state at all returns bad_oauth_callback with "OAuth state parameter missing" (supabase/auth: external.go).
Which cause is it?
| What you see | Cause | Fix |
|---|---|---|
| "OAuth state has expired", or flow_state_expired | The sign-in took too long and the state expired | Cause 1 |
| "OAuth state not found or expired", or "State has already been used" | The sign-in ran twice, or the callback ran again | Cause 2 |
| "OAuth state parameter is invalid" | The state came back changed, so it is not a valid ID | Cause 3 |
| Sign-in starts in one browser or device and finishes in another | The code exchange must run on the browser where the flow started | Cause 4 |
1. The sign-in took too long
Supabase's error page says the PKCE flow state "has expired" and that the fix is to "Ask the user to sign in again" (Supabase: Auth error codes). The Auth server returns "OAuth state has expired" for the same case (supabase/auth: external.go).
How to fix it
- Ask the person to start sign-in again from the sign-in button in your app.
- Our suggestion: test the whole sign-in again, and time how long the provider screens take.
Source: Supabase: Auth error codes, supabase/auth: external.go
2. The same sign-in ran twice, or the state was already used
The Auth server returns "OAuth state not found or expired" when no flow state matches the state ID. For a PKCE flow that already has a user, it returns the code flow_state_already_used with the message "State has already been used" (supabase/auth: external.go, supabase/auth: errorcode.go). Supabase's error page says flow_state_not_found means the "PKCE flow state ... no longer exists" (Supabase: Auth error codes).
How to fix it
- Start one sign-in and finish it. Do not reload the callback page or open it again from history.
- Our suggestion: check that a double click does not start a second sign-in.
- Our suggestion: start a new sign-in after a completed one, then confirm it works.
Source: supabase/auth: external.go, Supabase: Auth error codes
3. The callback changed the state value
Supabase describes the state as "data echoed back by the OAuth provider to Supabase Auth" (Supabase: Auth error codes). The Auth server returns "OAuth state parameter is invalid" when the value is not a valid ID (supabase/auth: external.go). The provider must send the callback to your Supabase project. For Google, the Supabase guide says to "Under Authorized redirect URIs add your Supabase project's callback URL" (Supabase: Google login). Supabase also says "The URL in redirectTo should match the Redirect URLs list configuration" (Supabase: Redirect URLs).
How to fix it
- In the provider's console, set the Authorized redirect URI to your Supabase project's callback URL. The Google guide gives the local form as
http://127.0.0.1:54321/auth/v1/callback. - Check that the
redirectToin your app matches an entry in the Redirect URLs list in Supabase.
Source: Supabase: Google login, Supabase: Redirect URLs, supabase/auth: external.go
4. The sign-in started in one browser and finished in another
Supabase's PKCE page says "The code verifier is created and stored locally when the Auth flow is first initiated," and that "the code exchange must be initiated on the same browser and device where the flow was started" (Supabase: PKCE flow).
How to fix it
- Start and finish the sign-in in the same browser.
- If the sign-in starts from an email link or on a phone, start it again in the browser where the person will finish it.
- Our suggestion: test on your live app domain in a private window, using the same browser for both steps.
Source: Supabase: PKCE flow
How do I check it's fixed?
- Our suggestion: in a private window, open your live app, not localhost. Click the sign-in button for your provider.
- Our suggestion: finish the provider's screens in the same window.
- Our suggestion: expect to land in the signed-in app, with no bad_oauth_state message.
- Our suggestion: sign out, then sign in again with the same provider to confirm a new sign-in starts cleanly.
FAQ
What is the difference between bad_oauth_state and bad_oauth_callback?
bad_oauth_callback means the callback from the provider does not have all the required attributes. The docs say that means the state is missing (Supabase: Auth error codes). bad_oauth_state means the state is there but is not usable.
What is bad_code_verifier?
It is a different PKCE error. Supabase's error page says it is "Returned from the PKCE flow where the provided code verifier does not match the expected one. Indicates a bug in the implementation of the client library." (Supabase: Auth error codes).
Does the Auth server compare the state with another value?
The source we read looks up the state ID and checks its expiry. It does not compare the state with a second value (supabase/auth: external.go).
Can VibeFix fix it for me?
Yes, for apps built in Lovable or any app whose code is on GitHub. The free check confirms the problem on your live app first. If you want it fixed, our AI agent finds the cause, fixes it in your code for $79 and tests your live app again. See pricing.
Related guides
- Supabase Google sign-in redirects to localhost in production
- Supabase redirect URL localhost
- Lovable sign-in works in preview but fails when published
Sources (official documentation)
- Supabase: Auth error codes
- Supabase: PKCE flow
- Supabase: Redirect URLs
- Supabase: Google login
- supabase/auth: internal/api/external.go
- supabase/auth: internal/api/apierrors/errorcode.go
Last checked: 17 November 2026.
VibeFix is independent. Supabase is a trademark of its owner.
More guides · Shopify store accessibility · About · Your privacy choices