auth: Flow State not found
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
I am using self-hosted supabase with gotrue and next js for auth. A few users can’t login to the app because they get redirected to the following page every time they try to sign in with google.
[GET] /auth/callback?next=%2F&error_description=Flow%20State%20not%20found&error=server_error status=307
I haven’t found anything unusual about these users.
On the client side I call
const { error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: `${window.location.origin}/auth/callback?next=${window.location.href}`,
queryParams: {
access_type: "offline",
prompt: "consent",
},
},
});
To Reproduce
I haven’t found why it happens to these specific users. They are using mobile chrome and using the same auth flow as other users. They tried logging in using multiple different google accounts.
- Go to https://climbest.app/
- Click on login
- Be lucky I guess?
- Get redirected to the
Flow State not founderror.
Expected behavior
Users can log in to the app.
Screenshots
System information
- User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36 - OS: Android 10
- Browser: Chrome 120
- Version of supabase-js: 2.39.0
- Version of Node.js: Node.js 18.x
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 28 (5 by maintainers)
We recently discovered that users clicked twice on the Google OAuth confirmation page, causing issues. The first click successfully triggers Supabase’s
/callback, but the second click fails because/callbackdeletes the flow state ID after the initial successful call.By the way, I’m using the Supabase cloud not self-hosted.
@J0
I’m getting this when trying to confirm emails using a callback url
const { error } = await supabase.auth.exchangeCodeForSession(code);
We’re also seeing this, it’s happening 20-40 times a day for our users. Redirect looks like this:
I’m initializing the client like this:
And using like this:
I think I copy-pasted code from https://supabase.com/docs/guides/auth/server-side/oauth-with-pkce-flow-for-ssr to my
climbclimb/src/app/auth/callback/route.ts:After
supabase.auth.exchangeCodeForSessionI returned a page that performed a redirect, when I just returnreturn NextResponse.redirect(requestUrl.origin);the problem goes away. I suspect its a race condition with setting/reading the cookieyes - i have GOTRUE_EXTERNAL_GOOGLE_REDIRECT_URI working with a hosted react site with an external self hosted supabaes ssl site - and basically the app hands off sign in to google - and then google successfully hits the external supabase endpoint - and then website comes good with the callback. it took a few days and eyeballs to work this out.
im self hosting - when i check docker container (ive gone through google sign in many times )
docker-compose logs auth i see the inserts i see the error -
https://mywebsite.com/auth/v1/token?grant_type=pkce
grant_type: pkce {auth_code: “4/0Ab_5qlmQXkW5fewhd38uT4GJu01KQM2-Uza3bnPKB1ucvLrliEpLjDqrZLyhT-oigaQprg”,…} auth_code : “4/0Ab_5qlmQXkW5fewhd38uT4GJu01KQM2-Uza3bnPKB1ucvLrliEpLjDqrZLyhT-oigaQprg” code_verifier : “c92db6530ed056b3754ac4598af499cdeda88ffd9ce1e11f9a3b1ea21504816b438ae7a5a0c315e1b5668882d32efd07d48a01f637d2dc87”
UPDATE re-reading @chris-feist - maybe this is root cause. timeout issue or cookie size on nginx. i do an audit by truncated the authflow table.
I’m having the same issue on google on self hosted…Any way to fix this ?
I’m having the same issue with GitHub as the provider. It’s frustrating to see this open for so long without any resolution.
What I realized was happening in my case is that during sign up, resource creation was taking longer than 5 seconds, so the oauth callback was retried. The retried request always failed with this error since I assume the code was already read/processed. I’m using Remix, so I ended up running async functions in parallel to speed up my loader and using Streaming for a better UX.
help same issue, kakao provider too— i handle itIn my case, the error occurred because Nginx received a header from Google that was too large to process
Same for us, google oauth suddenly doesn’t work 30% of the time.
Mostly for mobile users but also happens on Desktop.
Same for us, didn’t see any issue like for months, started to happening last week…
Hey, I am experiencing the same issue. I got this callback URL, unable to replicate it on my side. It was spotted on Pagesense logs.
#error=server_error&error_code=422&error_description=Flow+state+not+foundWe have seen that too, but only occasionally and I cannot reproduce that (hence can’t share more than just these):