小编Fua*_*ad9的帖子

如何解决生产中 next-auth 的 api/auth/error 问题?

我在 Vercel 中设置了以下环境变量:

NEXTAUTH_URL=https://example.vercel.app (production) 
NEXTAUTH_URL=http://localhost:3000 (development)
Run Code Online (Sandbox Code Playgroud)

然后在 Google 提供商 GCP 控制台 ( https://console.cloud.google.com )中授权以下两个重定向 URL :

https://example.vercel.app/api/auth/callback/google
http://localhost:3000/api/auth/callback/google
Run Code Online (Sandbox Code Playgroud)

当我单击登录按钮时,它会重定向到此错误 URL:https://example.vercel.app/api/auth/error并显示“找不到此页面”。我还尝试为环境变量设置这些值:

NEXTAUTH_URL=https://example.vercel.app/api/auth 
NEXTAUTH_URL=https://example.vercel.app/api/auth/signin
Run Code Online (Sandbox Code Playgroud)

错误仍然存​​在。在开发 ( https://localhost:3000) 中,我能够成功登录:单击登录按钮时,它会正确地将我重定向到以下 URL:

http://localhost:3000/api/auth/signin?callbackUrl=http%3A%2F%2Flocalhost%3A3000%2F
Run Code Online (Sandbox Code Playgroud)

并显示 NextAuth 默认页面:

浏览器img

我的身份验证API pages/api/auth/[...nextauth].js

NEXTAUTH_URL=https://example.vercel.app (production) 
NEXTAUTH_URL=http://localhost:3000 (development)
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?我错过了什么吗?

next.js next-auth

15
推荐指数
2
解决办法
5万
查看次数

标签 统计

next-auth ×1

next.js ×1