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

部署Vercel后NextAuth跳转/api/auth/error而非登录页的问题

NextAuth部署到Vercel后登录失败问题排查

问题现象

  • 本地环境运行正常,但部署到Vercel后无法登录,系统会重定向到/api/auth/error,显示提示:

"Server error
There is a problem with the server configuration.
Check the server logs for more information."

  • 日志记录:[GET] /api/auth/error?error=Configuration&nxtPnextauth=error status=500

已尝试的解决步骤

  • 已在生产环境配置NEXTAUTH_SECRET密钥
  • 尝试设置AUTH_TRUST_HOST为https://auclify.vercel.app/,之后改为true,问题仍未解决

相关配置详情

auth.ts代码

import { DrizzleAdapter } from "@auth/drizzle-adapter";
import NextAuth, { DefaultSession } from "next-auth";
import Google from "next-auth/providers/google";
import { database } from "@/db/database";
import { accounts, sessions, users, verificationTokens } from "@/db/schema";
import { env } from "@/env";

declare module "next-auth" {
  interface Session {
    user: {
      id: string;
    } & DefaultSession["user"];
  }
}
export const { handlers, signIn, signOut, auth } = NextAuth({
  adapter: DrizzleAdapter(database, {
    usersTable: users,
    accountsTable: accounts as any,
    sessionsTable: sessions,
    verificationTokensTable: verificationTokens,
  }),
  callbacks: {
    session({ session, user }) {
      session.user.id = user.id;
      return session;
    },
  },
  providers: [Google],
  secret: process.env.NEXTAUTH_SECRET,
});
  • 使用的NextAuth版本:5.0.0-beta.19

.env示例配置

DATABASE_URL=
AUTH_DRIZZLE_URL=
NODE_ENV=development
AUTH_SECRET=
AUTH_GOOGLE_ID=
AUTH_GOOGLE_SECRET=
BUCKET_NAME=
CLOUDFLARE_ACCESS_KEY_ID=
CLOUDFLARE_SECRET_ACCESS_KEY=
CLOUDFLARE_ACCOUNT_ID=
NEXT_PUBLIC_BUCKET_URL=
NEXT_PUBLIC_KNOCK_PUBLIC_API_KEY=
NEXT_PUBLIC_KNOCK_FEED_ID=

调试新增错误信息

添加调试后,获取到详细错误日志:

[31m[auth][error][0m AdapterError: Read more at https://errors.authjs.dev#adaptererror

[31m[auth][cause][0m: Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1606:16)
    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)

请问我哪里操作有误?


内容的提问来源于stack exchange,提问作者Anand MS

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 19:28:21