github oauth stuck in redirect loop
Hello kind folks,
I am using github oauth and resend, like in the demo boilerplate project when initializing a convex app with NextJS, convex auth, github oauth, and hosting on Vercel.
In development, login works.
In production, login actually works, the database receives the correct user data from github, but the front end crashes.
Opening the network tab reveals a slew of 302 redirects, followed by 308 redirects.
I am using NextJS, hosting on Vercel, with a domain.
I've checked:
- The middleware js file
- The environment variables
- The github oauth app id and key
- For the homepage url I used my production domain, though it seems to work in dev either way.
- For the github, the callback url for convex, followed the set up documentation a few times step by step
- Maybe my convex server + client providers are wrong?
What did I miss?
Any ideas?
21 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Have you seen https://labs.convex.dev/auth/production
Production - Convex Auth
Authentication library for your Convex backend
Yes, I followed it step by step.
Initially I had copied the convex env variables from dev to prod and then updated them one by one, however, the db is getting the user details correctly populated, just the redirect on success is bugging out.
Here's my middleware file:
the default code was never triggering the conditions anyway, and works in dev...
It's hard to guess what you missed. You could compare against https://github.com/get-convex/convex-auth/tree/main/test-nextjs
GitHub
convex-auth/test-nextjs at main · get-convex/convex-auth
Library for built-in auth. Contribute to get-convex/convex-auth development by creating an account on GitHub.
You might try deleting cookies+localstorage too, in case you previously set some bad state.. Tips in https://labs.convex.dev/auth/debugging can help.
Debugging - Convex Auth
Authentication library for your Convex backend
Can anyone make an account, could you send me the url to try?
I was comparing to projects, it's confusing how the providers are set up, I now have 3 providers.
Definitely deleted cookies, happens in private browser too.
https://www.easyhacks.org , does the page come up for you at all?
page comes up for me if I use this url: https://easy-hacks-umber.vercel.app
but crashes when I login/sign up.
EasyHacks 🔥
The open hackathon
Yep I get these redirects too
was that after login?
Or right away?
Oddly, the page did load the first time I visitted it. After I tried logging in it started doing the redirecs even in a private browser.
The code is here https://github.com/disrae/easyHacks
The fact that it's worse for the production domain and not for the temporary vercel subdomains also confuses me.
I don't know if the providers could be the culprit, kappa ai said I was mising one so I added it, I now have 3... 🤔
It made no difference to the symptoms.
That was right away, didn't see any page
Do you know what' s sending that redirect?
I assumed it would be the middleware but not really, no, and oddly it doesn't do it until you try to login if you use the vercel subdomain
https://easy-hacks-umber.vercel.app/
It does the same thing with the email login magic link.
auth endpoint appears to work.
I see you in the database too, logging in from github.
With that url I get sent to GitHub, GitHub sends me to the Convex backend, and then the Convex backend 302s me to
https://www.easyhacks.org/?code=03051637
, and then the 308s to https://www.easyhacks.org/?code=03051637
beginso you need to figure out where that 308 redirect is coming from
Could be a Cloudflare thing https://vercel.com/guides/resolve-err-too-many-redirects-when-using-cloudflare-proxy-with-vercel
ahhhhhh!
Could be a Next.js thing https://github.com/vercel/next.js/discussions/15432
Dunno, but it's up to something about your app, not Convex Auth I think
yeah looks like it
I would send you a tip despite being unemployed 😅 Highly appreciate your detective skills.
good luck!
That instantly fixed itttttttt.
Cloudflare was sending requests with HTTP, had to set the TLS setting to strict.