我正在学习 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,
我尝试了我所知道的一切,但正如之前所说,我对这个框架真的很陌生。
不确定您正在阅读什么文档,但通常
NextAuth
的返回值就是您将公开为 GET
和 POST
处理程序的值。尝试公开整个返回值,而不是 handlers.GET 和 handlers.POST