【发布时间】:2021-09-02 20:12:32
【问题描述】:
我已经在 Vercel 中设置了环境变量:
NEXTAUTH_URL=https://example.vercel.app (production)
NEXTAUTH_URL=http://localhost:3000 (development)
Google 提供商 GCP 控制台中的授权重定向 URL (https://console.cloud.google.com):
https://example.vercel.app/api/auth/callback/google
http://localhost:3000/api/auth/callback/google
当我单击我的登录按钮时,它会重定向到此网址:https://example.vercel.app/api/auth/error 并显示“找不到此页面”。我还尝试为环境变量设置这些值:
NEXTAUTH_URL=https://example.vercel.app/api/auth
NEXTAUTH_URL=https://example.vercel.app/api/auth/signin
但错误仍然存在。在开发中 (https://localhost:3000) 我能够成功登录,当我点击我的登录按钮时,它会将我重定向到这个 URL:
http://localhost:3000/api/auth/signin?callbackUrl=http%3A%2F%2Flocalhost%3A3000%2F
并显示:
我的身份验证 API (pages/api/auth/[...nextauth].js):
import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
export default NextAuth({
providers: [
Providers.Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
session: {
jwt: {
signingKey: {
kty: 'oct',
kid: `${process.env.kid}`,
alg: 'HS512',
k: `${process.env.k}`,
},
secret: `${process.env.SECRET}`,
},
},
debug: true,
theme: 'dark',
})
如何解决这个问题?我错过了什么吗?
【问题讨论】:
-
嗨@Fuad9 你能解决这个问题吗?