我正在使用next-auth并试图在服务器组件上获取serverSession,我正在使用Next。js 13 beta的应用程序目录和API目录也在应用程序目录,所以根据下一个认证文档,这是我如何可以得到serverSession
import { getServerSession } from "next-auth/next"
import { authOptions } from "pages/api/auth/[...nextauth]"
export default async function Page() {
const session = await getServerSession(authOptions)
return <pre>{JSON.stringify(session, null, 2)}</pre>
}
但是AuthOptions不可用,因为根据next-auth文档,这是我的API路由在next中应该看起来像。js 13测试版
import NextAuth from "next-auth"
const handler = NextAuth({
...
})
export { handler as GET, handler as POST }
因此没有authOptions要导入的请求
我该怎么做
谢谢
1条答案
按热度按时间p5cysglq1#
您可以简单地按照以下方式导出authOptions和handler: