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
matt
matt2mo ago
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.
matt
matt2mo ago
Loads here for around 10 seconds, then Vercel times it out.
No description
Eve
Eve2mo ago
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.
matt
matt2mo ago
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..
import NextAuth from "next-auth";
import { authOptions } from "~/server/auth";

// This function can run for a maximum of 30 seconds
export const config = {
maxDuration: 30,
};

export default NextAuth(authOptions);
import NextAuth from "next-auth";
import { authOptions } from "~/server/auth";

// This function can run for a maximum of 30 seconds
export const config = {
maxDuration: 30,
};

export default NextAuth(authOptions);
matt
matt2mo ago
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...
matt
matt2mo ago
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...
Want results from more Discord servers?
Add your server