I have a Next.js 13 app with a MySQL database and I am adding authentication via NextAuth. I am using the prisma adapter to use it as my ORM.
I have configured all as it is detailed in the guide (https://authjs.dev/reference/adapter/prisma).
When I click the "Sign in with Credentials" button from the default NextAuth page I am redirected to "https://localhost:3000/api/auth/callback/credentials" but it shows this error ERR_SSL_PROTOCOL_ERROR
This Site Can’t Provide a Secure Connection
.
The same happens when I click "Sign Out" in the signout page.
I tried disabling certificate verification with the env variable NODE_TLS_REJECT_UNAUTHORIZED=0
I have seen in this answer https://stackoverflow.com/a/58003959/11909334 .
Also tried to ignore the SSL error in chrome: "Since you are running your application on localhost for development purposes, you can simply ignore the SSL error. Most modern browsers provide an option to proceed despite the error. For example, in Chrome, you can click on "Advanced" and then select "Proceed to localhost (unsafe)"."
Also tried this solution https://github.com/prisma/prisma/discussions/19400#discussion-5225423 .
And tried other browsers like Microsoft Edge.
I found this person having the same error https://github.com/prisma/prisma/discussions/19494#discussion-5243149
Finally I found the error after a lot of hours of searching... I had my NEXTAUTH_URL defined as https://localhost:3000
with HTTPS instead of HTTP.
The solution consists only in replacing https://localhost:3000
with http://localhost:3000
in the .env file.