'Next Auth: Deployed code redirecting me to localhost on login

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!



Solution 1:[1]

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: [...] })

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Connor