You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NextAuth Google Provider OAuth回调超时问题求助(WSL2环境)

WSL2下NextAuth Google Provider请求超时3500ms问题排查与解决

问题背景

  • 运行环境:Windows 11 + WSL2,技术栈为Next.js 13 + NextAuth + Google Provider + Prisma Adapter
  • 异常现象:首次配置完成后登录正常,后续触发[next-auth][error][OAUTH_CALLBACK_ERROR]错误,提示请求超时3500ms
  • 无效尝试:重启WiFi、切换移动数据、重启电脑、修改NextAuthOptions超时时间
  • 对比验证:GitHub Provider可正常完成授权登录

完整错误日志

[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error outgoing request timed out after 3500ms {
  error: RPError: outgoing request timed out after 3500ms
      at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/openid-client@5.4.3/node_modules/openid-client/lib/helpers/request.js:115:19)
      at async Issuer.discover (webpack-internal:///(rsc)/./node_modules/.pnpm/openid-client@5.4.3/node_modules/openid-client/lib/issuer.js:135:30)
      at async openidClient (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.23.0_next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/lib/oauth/client.js:12:18)
      at async oAuthCallback (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.23.0_next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/lib/oauth/callback.js:94:24)
      at async Object.callback (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.23.0_next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/routes/callback.js:18:79)
      at async AuthHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.23.0_next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/index.js:202:38)
      at async NextAuthRouteHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.23.0_next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:50:30)
      at async NextAuth._args$ (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.23.0_next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:84:24)
      at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37) {
    name: 'OAuthCallbackError',
    code: undefined
  },
  providerId: 'google',
  message: 'outgoing request timed out after 3500ms'
}

WSL环境版本信息

WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.2134

解决方案

1. 修复WSL2 DNS配置

WSL2默认DNS可能无法正常解析Google OAuth相关域名,导致请求超时:

  • 编辑WSL内的/etc/resolv.conf,添加公共DNS:
    echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
    
  • 创建/etc/wsl.conf防止DNS被自动重置:
    [network]
    generateResolvConf = false
    
  • 重启WSL:在Windows终端执行wsl --shutdown,再重新启动WSL会话

2. 延长OpenID Client请求超时

NextAuth依赖的openid-client默认超时较短,针对Google Provider单独配置超时:

export const authOptions: NextAuthOptions = {
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
      timeout: 10000 // 延长至10秒
    }),
  ],
  adapter: PrismaAdapter(prisma),
  // 其他配置...
};

3. 排查WSL网络代理问题

若Windows端开启代理,WSL需正确配置代理或关闭:

  • 检查WSL内代理环境变量:
    echo $http_proxy
    echo $https_proxy
    
  • 若不需要代理,清空变量:
    unset http_proxy
    unset https_proxy
    
  • 若使用代理,确保地址为Windows主机IP(如http://192.168.1.100:7890),而非localhost

4. 复查Google OAuth应用配置

确认Google Cloud Console中的应用配置无误:

  • 检查已授权的重定向URI是否包含当前应用的回调地址(如http://localhost:3000/api/auth/callback/google)
  • 若应用处于测试状态,确保当前登录账号已添加至测试用户列表

内容的提问来源于stack exchange,提问作者Anurag Singh Chauhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 14:35:35