gitaan
gitaan

Reputation: 9

NextAuth Nextjs13 always calling localhost on Vercel

I created a simple project to test NextAuth and it works well on localhost. When I deploy to Vercel, access api/auth/signin and try to login, it tries to call localhost:3000 credentials instead of the Vercel server.

I tried to set the env variable NEXTAUTH_URL on my localhost as google.com just to test, and it works, it redirects me to google.com when using signin. But on Vercel no matter what NEXTAUTH_URL I try, it always tries to call localhost:3000. (Other env variables on Vercel work, like my database) I'm using Next.js 13 with the app directory

NEXTAUTH_URL Vercel google.com

Upvotes: 0

Views: 1222

Answers (3)

Fakhrul Islam Fuad
Fakhrul Islam Fuad

Reputation: 911

I guess you need to check your google cloud console credentials of your Oauth client.enter image description here

You need to add your custom URL there.

Upvotes: 0

hellodamien
hellodamien

Reputation: 1

It's an issue with [email protected] and Route Handler support. When deployed on Vercel, NextAuth is detecting host from headers x-forwarded-host and skipping NEXTAUTH_URL. But with Next 13 Route Handler, we have to use a new headers() method to read from request, which not used by NextAuth. I opened a PR to fix this, waiting to be reviewed : https://github.com/nextauthjs/next-auth/pull/7220

Upvotes: 0

gitaan
gitaan

Reputation: 9

I solved it. It is a problem with the pull request that I was using for NextAuth, that adds support to run NextAuth on the app directory, but apparently it has that problem on Vercel. Will post there.

Upvotes: 0

Related Questions