0

When trying to login with next-auth, I get 500 from /api/auth/providers and "Internal Server Error" as the only message on the screen. This works great locally, but not in production. I use Netlify to host the project.

How do I fix these server issues?

packages:

  • "dotenv": "^16.0.1",
  • "next": "^13.2.4",
  • "next-auth": "^4.20.1",
  • "next-auth-sanity": "^1.4.8",
  • "next-connect": "^1.0.0",
  • "next-pwa": "^5.5.2",
  • "next-sanity": "^4.1.5",
  • "react": "^18.2.0",

Engine:

  • "node": "18.x"

Network messages

Before trying to login, next-auth already recognizes that there's something wrong and suggests it's the NEXTAUTH_URL that's incorrect. This value is set as localhost:3000 in the local environment and https://my-domain.com in Netlify. The value is also set for all scopes. The same goes for the NEXTAUTH_SECRET value

Errors from next-auth

The login component looks like this and it fails in the try/catch. The adapter I'm using is Sanity CMS. Again, this works fine locally.

enter image description here

Lastly this is the `[...nextauth].js with the options.

enter image description here

1 Answer 1

0

So I noticed that I accidentally added a "/" at the end of the NEXTAUTH_URL which caused the issue. I removed it and now it works both locally and in production.

tldr: NEXTAUTH_URL="https://example.com/" --> NEXTAUTH_URL="https://example.com"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.