Samuel
Samuel

Reputation: 51

Next.js with Next-Auth: 504 Timeout Error on Production Server

I have developed a simple Next.js app with authentication using Next-Auth. Everything works perfectly fine when running the app locally with environment variables configured in .env.local. However, when I deploy the app to my production server and update the environment variables accordingly, I encounter a 504 timeout error when attempting to log in.

Here is my Development setup:

Here is my Production setup:


When I access the login page and submit the form with valid credentials in the production environment, the app sends a POST request to https://my_domain.com/api/auth/callback/credentials, but I'm consistently receiving a 504 timeout error, and the authentication process doesn't complete.

I've checked the server's internet access, verified that the environment variables are correct, and ensured that the API is accessible over HTTPS. I'm not sure what else to investigate to resolve this issue.

I also experimented with my development setup, where I connected to my production server's API, and everything functioned perfectly. However, the challenge arises when attempting authentication within my Next.js application deployed on the production server with the modified NEXTAUTH_URL. In this specific server configuration, authentication does not seem to work as expected.

Any suggestions or insights into what might be causing this timeout error would be greatly appreciated. Thank you!

Upvotes: 1

Views: 1496

Answers (2)

Asikur Rahman
Asikur Rahman

Reputation: 1

Just Remove this line from production environment::: NEXT_AUTH_URL =- i'm sure your problem will be solve

Upvotes: 0

I've just had this same error (504) when trying to login in production using c NextAuth credentials.

I noticed that I didn't have any NEXT_AUTH_URL env in Vercel, in my production envs.

After adding it, the problem seem to have been gone. At least so far.

Where are you deploying your application? If it's in Vercel, I recommend you also add your env variables there. I had many production errors for missing it.

Upvotes: 0

Related Questions