如何在新版本next js 13.2 app dir api路由中使用nextAuth的[...nextauth]动态路由?

Sey*_*eyT 4 next.js next-auth next.js13

目前pages/api/auth目录下的[\xe2\x80\xa6nextauth].ts文件工作正常。但是,我想迁移到 Next.js 13.2\xe2\x80\x99s 应用程序目录 API 路由,但无法\xe2\x80\x99t 找到迁移我的 nextAuth 路由的方法。我尝试将 /pages/api/auth/[\xe2\x80\xa6nextauth].ts 移动到 app/api/auth/[\xe2\x80\xa6nextauth].ts 但它\xe2\x80\x99s 不起作用。

\n

小智 6

next-auth 文档建议Next 13.2+使用以下方法

/app/api/auth/[...nextauth]/route.ts <- file strucure

import NextAuth from "next-auth"

const handler = NextAuth({
  ...
})

export { handler as GET, handler as POST }
Run Code Online (Sandbox Code Playgroud)


Ahm*_*bai 5

API 路由

API 路由继续在pages/api 目录中工作,没有任何更改。但是,它们已被应用程序目录中的路由处理程序取代。

这就是新的结构:/app/api/auth/[...nextauth]/route.js