Authentication flow: Received: null | Expected: State not found (Next14, Vercel)

I've built V1 of my app, and auth is working fine locally. After deploying to vercel, I am getting the above error when attempting to login. If I navigate to the app again after this happens, it turns out I AM actually logged in, which makes me think it is an issue with redirects. I have confirmed my vercel environment variables match my kinde config
15 Replies
Yoshify
Yoshify3w ago
Are you using Vercels deployment protection by any chance? The only situation I’ve personally encountered this (assuming you’ve done the rest of the setup correct, as you’ve stated) is when I had deployment protection enabled. Vercels deployment protection auth redirect was hijacking Kindes post login redirect.
Zer0Down
Zer0DownOP3w ago
Really appreacite the suggestion. I've turned it off, but still getting the same issue. Really frustrating, as it worked perfectly locally. I'm almost at the point where I just go back to Clerk - 3 hours down on this today already
Yoshify
Yoshify3w ago
I can understand the frustration, losing 3 hours of work is a PITA. What do your callback URLs for your application in the Kinde dashboard look like? Are they pointing to your Vercel URLs?
Yoshify
Yoshify3w ago
There’s a great write up in this GitHub comment about why this error occurs and the common fixes
GitHub
Bug: Authentication flow state · Issue #86 · kinde-oss/kinde-auth-n...
Prerequisites I have searched the repository’s issues and Kinde community to ensure my issue isn’t a duplicate I have checked the latest version of the library to replicate my issue I have read the...
Zer0Down
Zer0DownOP3w ago
Yeah, I've checked and double checked my env variables set in vercel/kinde: KINDE_POST_LOGIN_REDIRECT_URL: https://task-badger.vercel.app/api/auth/kinde_callback Allowed callback URLs: http://localhost:3000/api/auth/kinde_callback https://task-badger.vercel.app/api/auth/kinde_callback found that post earlier, but it seems to be referring to preview urls, and I don't think I'm using them?
Zer0Down
Zer0DownOP3w ago
SamHudson
SamHudson
Proudly protected by Kinde
Yoshify
Yoshify3w ago
Can I also confirm your production environment has been built/rebuilt since setting those environment variables in Vercel?
Zer0Down
Zer0DownOP3w ago
Yeah mate - I've probably redeployed 15+ times since I started
Yoshify
Yoshify3w ago
Are you using the KINDE_COOKIE_DOMAIN env var by any chance?
Zer0Down
Zer0DownOP3w ago
Yes, that's one of the things I've tried.
Yoshify
Yoshify3w ago
Could you try rebuilding with that removed? Just going off the network inspector when it tries to set the state cookie it's attempting to set it for Domain=.task-badger.vercel.app; but your auth is on https://samhudson.kinde.com/ KINDE_COOKIE_DOMAIN from my understanding is if you're using a custom Kinde domain and your authentication flow starts and ends on the same domain (at different subdomains), e.g., your app is at app.X.com and your Kinde custom domain is auth.X.com
Zer0Down
Zer0DownOP3w ago
Cheers for the help dude. I had the issue before using it - it was one of the things I tried. I'm kind of done with Kinde now I think, I know I can get Clerk spun up in a hour or so, so I'm off to do that (after going outside to touch grass) You're a legend though mate, appreciate your time
Yoshify
Yoshify3w ago
I mean... it works 😛 I just logged in. I think we were looking at 2 issues here - Vercel Deployment Protection + incorrect use of KINDE_COOKIE_DOMAIN (you may want to delete the little Test Tester account I've created to help you! ) Hoping you stick around now that it's working, Kinde really does have a lot to offer (I'm not affiliated, just an avid user) - if not I understand, and glad I could help you out regardless!
Zer0Down
Zer0DownOP3w ago
Yes, it does work - but not on my desktop. So weird. Just tried it on my phone and all good, apart from a 404 because I messed up the redirect. Thanks so much mate!! And now it works on my desktop. Guess I'll stick around
Yoshify
Yoshify3w ago
Glad to hear it 🙌
Want results from more Discord servers?
Add your server