I'm having an issue with Auth.js (NextAuth) v5 in my Next.js application when deploying with Dokploy
I'm having an issue with Auth.js (NextAuth) v5 in my Next.js application when deploying with Dokploy on my VPS server. The providers' URLs are showing localhost:3000 instead of my production domain.
Environment:
- Next.js 15
- Auth.js (NextAuth) v5
- Deployed using Dokploy
- Running behind Cloudflare proxy
Issue:
When I check the
/api/auth/providers
endpoint in production, it shows:
```json
{
"google": {
"id": "google",
"name": "Google",
"type": "oidc",
"signinUrl": "http://localhost:3000/api/auth/signin/google",
"callbackUrl": "http://localhost:3000/api/auth/callback/google"
}
}
Expected behavior:
The URLs should show my production domain instead of localhost:3000.
What I've tried:
Setting environment variables:
NEXT_PUBLIC_APP_URL=https://mydomain.com
AUTH_SECRET=[my-secret]
AUTH_TRUST_HOST=true
The same setup works correctly when deployed to Vercel, but fails on my VPS server deployment.
When I add AUTH_URL=https://mydomain.com to env in production:
The providers show the correct domain:
{
"google": {
"id": "google",
"name": "Google",
"type": "oidc",
"signinUrl": "http://mydomain.com/api/auth/signin/google",
"callbackUrl": "http://mydomain.com/api/auth/callback/google"
}
}
BUT Cloudflare returns error 10000 on the homepage
How can I make Auth.js use my production domain instead of localhost while avoiding the Cloudflare error?
ps: cloudflare set to FULL ssl/tls5 Replies
running the same setup, no error for me lol
you must be hardcoding localhost somewhere
not sure why you'd even have localhost showing up in your production environment
When I deploy on Vercel, I have no problems with it.
Vercel automatically create the environment variables for you check the docs for auth.js
Thank you, bro! You helped me so much. In step 3: 'Set the source code and build type,' it says:
Set the source code to the repository and set the build type to Dockerfile.
Where can I get the Dockerfile, and what should it look like?
if i build with Nixpacks, i get error from Cloudflare on my home page Error 1000 Ray ID: 900bee8efa6ba00e • 2025-01-12 08:56:11 UTC
DNS points to prohibited IP
but my DNS are correct
If I remove AUTH_URL=https://example.com/api/auth from the .env file and rebuild the application, the site works fine. However, at https://example.com/api/auth/providers, it still shows my localhost:3000
same thing if i build with Docker file , it successfull but still cloudflare error
maybe the error while i am using next-intl ?
it was problem in middleware while i am using one middleware next-intl and auth.js