next-auth google 提供商无法正常工作,访问被阻止:此应用程序的请求无效

2024-05-04

这整个星​​期我都在摸索。我已经尝试了几乎所有的方法。我正在尝试使用 next-auth + google 提供商。

在 GCP 中,在授权网址和重定向网址中: 本地主机:3000 真实域名网站

本地主机:3000/api/auth/callback/google realdomain.com/api/auth/callback/google

[...nextauth].js:

import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import FacebookProvider from "next-auth/providers/facebook";

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET
    }),
    FacebookProvider({
      clientId: process.env.FACEBOOK_CLIENT_ID,
      clientSecret: process.env.FACEBOOK_CLIENT_SECRET
    })
  ],
  secret: process.env.NEXTAUTH_SECRET,
  callbacks: {
    async session({ session, token }) {
      return session;
    },
  },
})

NEXTAUTH_URL=realdomain.com

通过上面的配置,它可以在本地运行。但在生产中,它总是重定向到 localhost:3000/api/auth/callback/google 并且不起作用。所以,我删除了GCP中的所有本地域,仍然不起作用。需要注意一件事: 当我console.log(providers)时 即使在生产应用程序中也是如此:

google: Object { id: "google", name: "Google", type: "oauth", … }
​​
callbackUrl: "http://localhost:3000/api/auth/callback/google"
​​
id: "google"
​​
name: "Google"
​​
signinUrl: "http://localhost:3000/api/auth/signin/google"
​​
type: "oauth"

仍然是本地主机。 错误:

Access blocked: This app’s request is invalid
Error 400: redirect_uri_mismatch

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you're the app developer, register the redirect URI in the Google Cloud Console.
Request details: redirect_uri=http://localhost:3000/api/auth/callback/google

“下一个验证”:“^4.20.1”

thanks!


*** NEXTAUTH_UR="域名" ***

在我的环境文件中添加上面还更新了我的谷歌控制台开发人员,它对我来说工作正常,(next 13 & next-auth 4.22.1)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

next-auth google 提供商无法正常工作,访问被阻止:此应用程序的请求无效 的相关文章

随机推荐