下一个身份验证获取和发布问题:无法读取未定义的属性(读取“GET”)

问题描述 投票:0回答:1

我正在学习 next.js,现在正在开发一个项目。我在学习next-auth时遇到问题,卡在项目中了:/

我的项目的

next.js 版本是 14.1.4

src\auth.ts:

import NextAuth from "next-auth/next";
import GoogleProvider from "next-auth/providers/google";
export const {
  handlers: { GET, POST },
  auth,
  signIn,
  signOut,
} = NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    }),
  ],
});

src\app\api\auth\[...nextauth\]\route.ts:

export { GET, POST } from "@/auth";

然后我尝试进入登录页面:http://localhost:3000/api/auth/signin

并遇到此错误:

服务器错误 类型错误:无法读取未定义的属性(读取“GET”)

生成页面时发生此错误。任何控制台日志都将显示在终端窗口中。 来源 src uth.ts (4:14) @ GET

 2 | import GoogleProvider from "next-auth/providers/google";
  3 | export const {`your text`
> 4 | handlers: { GET, POST },
    |            ^
  5 | auth,
  6 | signIn,
  7 | signOut,

我尝试了我所知道的一切,但正如之前所说,我对这个框架真的很陌生。

next.js next-auth
1个回答
0
投票

不确定您正在阅读什么文档,但通常

NextAuth
的返回值就是您将公开为
GET
POST
处理程序的值。尝试公开整个返回值,而不是 handlers.GET 和 handlers.POST

© www.soinside.com 2019 - 2024. All rights reserved.