Next Auth: Deployed code redirecting me to localhost on login

Viewed 2449

As the title suggests - I have a nextjs application that works absolutely fine locally - However, now I've deployed it to a dev environment, something really weird is happening.

I've deployed my application to a dev environment, and set my NEXTAUTH_URL Environment Variable to my development domain dev.mydomain.com. However when I login it redirects me to localhost:3000 . The weird thing is, if I have my local server running, and I change the port it runs on to say :4000, the actual website redirects me to localhost:4000... It's like it knows where my code is running locally with no reference to it?

Does anyone know what's going on here? I'm very confused - There's no reference to localhost in my codebase whatsoever, never mind the specific ports!

3 Answers

Make sure to include "site" as a key in the object you pass to NextAuth, with the value of your environmental variable. For example:

NextAuth({site: process.env.NEXTAUTH_URL, providers: [...] })

Don't forget to add the site to your configuration of your NextAuth instance because I believe it redirects to localhost:3000 by default.

Be sure to add NEXTAUTH_URL to your env variable config on your cloud server.

Related