下一个身份验证 - Oauth

问题描述 投票:0回答:1

我有我的下一个应用程序,它正在工作,但从今天开始,我不知道当我尝试使用谷歌登录时遇到这个错误,我使用下一个身份验证,这是我收到的请求:

终端打印出以下内容:

如何解决这个问题?我已经尝试更改客户端 ID 和 Secret 但仍然相同

这是下一个验证码:

const authOptions = {
  providers: [
    // OAuth authentication providers...
    GoogleProvider({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET,
      authorizationUrl:
      "https://accounts.google.com/o/oauth2/v2/auth?propmt=consent&access_type=offline&response_type=code",
    })
    
  ],
  secret: process.env.NEXTAUTH_SECRET,
  adapter: MongoDBAdapter(clientPromise),
  callbacks: {
    async signIn({ account, profile }) {
      if (account.provider === "google") {
        return profile.email_verified && profile.email.endsWith("@gmail.com")
      }
      return true // Do different verification for other providers that don't have `email_verified`
    },
    session: ({session, token, user}) => {
      if (adminEmails.includes(session?.user?.email)) {
        return session;
      }
      else {
        return false;
      }
    },
  },
}

export default NextAuth(authOptions)

export async function isAdminRequest(req,res) {
  const session = await getServerSession(req,res,authOptions);
  if (!adminEmails.includes(session?.user?.email)) {
    res.status(401);
    res.end();
    throw 'not admin';
  }
}
javascript oauth google-oauth next-auth next
1个回答
0
投票

我刚刚解决了这个问题,错误很简单,只需检查正确的端口即可,我使用的是 3001,但我将设置设置为 3000。

© www.soinside.com 2019 - 2024. All rights reserved.