Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 753
Nick Avatar asked Sep 02 '25 09:09

Nick


2 Answers

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

like image 126
Lodz Avatar answered Sep 05 '25 00:09

Lodz


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

like image 25
Connor Avatar answered Sep 05 '25 01:09

Connor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!