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:
Engine:
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
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.
Lastly this is the `[...nextauth].js with the options.
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"