Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

问题咨询:Google 登录报错同时 GitHub 登录正常怎么解? #1

Open
nemotica opened this issue Sep 20, 2024 · 0 comments

Comments

@nemotica
Copy link

tony 你好!首先感谢你提供的模板,格式内容和代码结构都很清晰明了,可读性很强,对初学者很友好,已加星🌟。

我在本地开发的时候遇到了如题所示的问题,使用 Google 登录会超时报错,但同时 GitHub 登录正常。想请教一下该如何解决。

  • 开发环境:MBP M2 + 最新版 Chrome + Cursor,node v20.11.0,npm 10.2.4,"next-auth": "^4.24.7", "oauth": "^0.9.15", "openid-client": "^5.4.0",
  • 复现步骤:点击首页导航栏右上角 login 展开弹窗,在弹窗中点击 Google 登录按钮,等待 x 秒后页面跳转到报错页面
  • 复现步骤截图
截屏2024-09-20 11 38 29 - **Google Cloud 凭据配置** : .env.local 和 .env.production 中的凭据字段,无论配成相同的凭证还是不同的两个凭证,都会超时报错 截屏2024-09-20 11 42 52 截屏2024-09-20 11 47 07
  • 我还尝试了以下方法
  1. 增加 GoogleProvider 等待时长( httpOptions:{timeout:50000} ),仍然报错
  2. 参考 Google Oauth failed when Github runs ok : Server error There is a problem with the server configuration.  nextauthjs/next-auth#10089 的建议更改 Google Cloud 凭据配置参数,仍然报错
    a. local 和 production 都换成同一个凭据,且在凭据中增加 http://localhost(信任源)和 http://localhost/api/auth/callback/google(回调 URI)
    b. local 和 production 都换成同一个凭据,且在 a 基础上把线上域名和 localhost:3000 都加到信任源和回调 uri
    c. local 和 production 都换成同一个凭据,且在 b 基础上额外增加 http://localhost(不加端口 3000),回调也加
  3. 隐私模式打开,仍然报错
  4. 切换到手机热点,仍然报错
  5. 部署到 Vercel 检查线上流程,线上生产环境报错
  • 相关代码
    `
    //src/app/api/auth/[...nextauth]/option.ts
    export const authOptions: NextAuthOptions = {
    // Secret for Next-auth, without this JWT encryption/decryption won't work
    secret: process.env.NEXTAUTH_SECRET,

    // Configure one or more authentication providers
    providers: [
    GithubProvider({
    clientId: process.env.GITHUB_APP_CLIENT_ID as string,
    clientSecret: process.env.GITHUB_APP_CLIENT_SECRET as string,
    }),
    GoogleProvider({
    clientId: process.env.GOOGLE_CLIENT_ID as string,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    httpOptions: {
    timeout: 50000,
    //agent: proxyAgent,
    },
    }),
    ],

    debug: true,

    pages: {
    //signIn: "/auth/login",
    },
    };
    //src/app/api/auth/[...nextauth]/route.ts
    //这里的代码没有改过
    import NextAuth from "next-auth";
    import { authOptions } from "./option";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
//.env.local
GITHUB_APP_CLIENT_ID="Ov2****" //已隐藏部分密码,下同
GITHUB_APP_CLIENT_SECRET="313****"

GOOGLE_CLIENT_ID="614****"
GOOGLE_CLIENT_SECRET="GOC****"

NEXTAUTH_SECRET="OtA****"
NEXTAUTH_URL="http://localhost:3000" # 开发环境`

`//.env.production
GITHUB_APP_CLIENT_ID="Ov2****" //与.env.local 配置相同
GITHUB_APP_CLIENT_SECRET="313****" //与.env.local 配置相同

GOOGLE_CLIENT_ID="614****" //与.env.local 配置相同
GOOGLE_CLIENT_SECRET="GOC****" //与.env.local 配置相同

NEXTAUTH_SECRET="OtA****" //与.env.local 配置不同
NEXTAUTH_URL="https://test-running-dev.vercel.app" # 生产环境`

预期逻辑 :希望本地开发环境和线上生产环境都可以正常登录 Google。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant