我在 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 默认页面:
pages/api/auth/[...nextauth].js
:NEXTAUTH_URL=https://example.vercel.app (production)
NEXTAUTH_URL=http://localhost:3000 (development)
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?我错过了什么吗?