NextAuth v4 auth timing out when deployed to Vercel, but works locally
I've been having an issue the past 4 hours trying to figure out why exactly my app works locally with Discord OAuth, but when deploying to vercel, it times out.
It seems like im getting a 200 when hitting discords authorize API:
https://discord.com/api/v9/oauth2/authorize
After I get a 200, it spins on Discords OAuth, because it can't redirect to my apps path:
/api/auth/callback/discord?code={code_here}
Any help is greatly appreciated as I really can't figure out what's going on!
6 Replies
Feel free to try it yourself if you'd like
https://cards-beyond-humanity.vercel.app/
Open network tab after signing in with Discord and you'll notice it just times out.
Loads here for around 10 seconds, then Vercel times it out.
I'm going to guess your Oauth callback url is still set up to localhost when you deploy, so your app is never receiving the callback.
would that be the NEXTAUTH_URL env variable?
the redirect URI in the oauth2/authorize call to Discord is set to
https%3A%2F%2Fcards-beyond-humanity.vercel.app%2Fapi%2Fauth%2Fcallback%2Fdiscord
that seems correct unless im missing something
I dont see how a incorrect callbkack uri would cause an API call to hang
any other possible ideas? I believe that is all set up correctly
I even set a config on my [...nextauth].ts file to extend the timeout for up to 30 seconds. It still just hangs for the ENTIRE 30 seconds then times out..
Looks like this post has the EXACT issue im having too: https://github.com/nextauthjs/next-auth/discussions/5057
GitHub
Sign in callback timeout in production · nextauthjs next-auth · Dis...
I'm using NextAuth with Google as the provider for users to login for my application. During development on localhost:3000, I have no issues logging in. However, when I try to login as a user a...
except this is with Google and im using Discord, but exact same idea and issue
I figured it out... mongodb did allow access unless I specified...