ERR_SSL_PROTOCOL_ERROR 使用 NextAuth + Prisma 在本地主机中

huangapple go评论58阅读模式
英文:

ERR_SSL_PROTOCOL_ERROR using NextAuth + Prisma in localhost

问题

我有一个使用Next.js 13和MySQL数据库的应用程序,并正在通过NextAuth添加身份验证。我正在使用prisma适配器将其用作我的ORM。

我已按照指南中详细说明的步骤进行了配置(https://authjs.dev/reference/adapter/prisma)。

当我点击默认NextAuth页面上的“使用凭据登录”按钮时,我被重定向到“https://localhost:3000/api/auth/callback/credentials”,但显示了以下错误:ERR_SSL_PROTOCOL_ERROR 此站点无法提供安全连接

在退出页面上点击“退出”时也发生同样的情况。

我尝试使用环境变量NODE_TLS_REJECT_UNAUTHORIZED=0来禁用证书验证,这是我在这个答案中看到的:https://stackoverflow.com/a/58003959/11909334。

还尝试在Chrome浏览器中忽略SSL错误:“由于您正在用于开发目的的本地主机上运行应用程序,因此您可以简单地忽略SSL错误。大多数现代浏览器提供了忽略错误的选项。例如,在Chrome中,您可以点击“高级”,然后选择“继续前往localhost(不安全)”。”

还尝试了这个解决方案:https://github.com/prisma/prisma/discussions/19400#discussion-5225423。

并尝试了其他浏览器,如Microsoft Edge。

我发现有人遇到了相同的错误:https://github.com/prisma/prisma/discussions/19494#discussion-5243149。

英文:

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

答案1

得分: 3

最终,在经过多小时的搜索后,我找到了错误... 我将我的NEXTAUTH_URL定义为https://localhost:3000,而不是HTTP。

解决方案只需在.env文件中将https://localhost:3000替换为http://localhost:3000

英文:

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.

huangapple
  • 本文由 发表于 2023年5月30日 02:30:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76359619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定