NextAuth not working with nginx reverse proxy #8089
Replies: 4 comments 2 replies
-
|
Resolved - it turns out to have been an issue with the environmental variables not being properly loaded in the DockerFile and docker-compose.yml instructions |
Beta Was this translation helpful? Give feedback.
-
|
Did you set your |
Beta Was this translation helpful? Give feedback.
-
|
I have tried with AUTH_TRUST_HOST =http://localhost:3000 as the application was running in http://localhost:3000 in pm2, it worked for me |
Beta Was this translation helpful? Give feedback.
-
|
I’m having a similar issue in production. I’m deploying my app with PM2 and Nginx, without Docker. The PM2 process is running on localhost:4011. After the Google OAuth flow finishes, the app redirects me to localhost:4011/login. However, it should be redirecting to mydomain.com/api/auth/callback/google. Everything works correctly in development, and the problem only happens in production. I’ve already set both NEXTAUTH_URL and AUTH_URL in my .env file. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all, my NextAuth implementation works locally but not when I deploy to my server with a nginx reverse proxy.
I deployed my NextJS app (the T3 demo) app using docker-compose to a bare metal linux server, following this tutorial (https://www.digitalocean.com/community/tutorials/how-to-secure-a-containerized-node-js-application-with-nginx-let-s-encrypt-and-docker-compose) to setup with HTTPS via nginx.
The Discord provider that works fine locally in developer mode (localhost:3000). But, when I deploy it through docker-compose,
while every other feature works as expected, when I press the login button from the , I get navigated to MYDOMAIN/api/auth/error, and an HTML page returns with the text "Internal Server Error". There is nothing on the server side or client side console about this error.
My .env file has
NEXTAUTH_SECRET="..."
NEXTAUTH_URL="https://mydomain/"
NEXTAUTH_URL_INTERNAL="https://website.ip.address/"
My discord provider has the following redirect URIs
http://localhost:3000/api/auth/callback/discord
https://mydomain/api/auth/callback/discord
I'm thinking there is something going on with the reverse proxy of nginx that's messing with nextauth. Let me know if anything in the attached nginx.conf file would cause this problem, or if there is any simple error.
nginx.conf.txt
Beta Was this translation helpful? Give feedback.
All reactions