我有使用 GitHub 提供程序进行 next-auth 的 Next.js 应用程序。我在 GitHub OAuth 页面上创建了一个新应用程序并获取了客户端 ID 和客户端密钥。然后我按照 next-auth 文档中的确切步骤进行设置:
问题是,当我在应用程序中单击“使用 GitHub 登录”时,我收到
OperationProcessingError: "response" body "access_token" property must be a non-empty string
。
首先,我被重定向到 GitHub,然后我允许访问我的 GitHub 信息,然后重定向回来,然后发生错误。
我尝试重新创建 GitHub OAuth 应用程序并执行 next-auth 文档中的相同步骤,但错误仍然存在。
GitHub OAuth 应用仪表板显示新用户已创建。
套餐版本:
auth.js
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { signIn, signOut, auth, handlers } = NextAuth({
providers: [GitHub],
});
中间件.js
export { auth as middleware } from "@/auth";
app/api/auth/[...nextauth]/route.js
import { handlers } from "@/auth";
export const { GET, POST } = handlers;
组件/sign-in.jsx
import { signIn } from "@/auth";
export function SignIn() {
return (
<form
action={async () => {
"use server";
await signIn("github");
}}
>
<button type="submit">Signin with GitHub</button>
</form>
);
}
检查并确保您的配置中有正确的 AUTH_GITHUB_SECRET。我遇到了同样的错误,结果发现我在该变量中配置了一些错误,修复了它并正常登录。