小编Sha*_*san的帖子

如何在应用程序目录中的 next js 13 beta 服务器组件中使用 next auth getServerSession

我将 next auth v4 与 next js 13 beta 和服务器组件一起使用,一切正常。但我有一种情况,我需要知道登录的用户 ID,因为我正在使用下一个身份验证,我可以访问会话,我可以使用 useSession() 但随后我需要使该组件成为客户端组件,所以我想在服务器上使用它,我可以在 API 中使用 getServerSession 因为我可以访问 req & res 对象,但在下一个带有新应用程序目录的 js beta 中,我不能这样做。如果您知道如何解决该问题,请告诉我。谢谢

import { getServerSession } from "next-auth";
import { authOptions } from "@/pages/api/auth/[...nextauth]";

const Test = async () => {
    const user_id = 1; // How do I get user id from session, user_id is available in session

    // I don't have access req & res object in server component.
    const data = await getServerSession(request, response, authOptions); …
Run Code Online (Sandbox Code Playgroud)

beta session prisma next-auth next.js13

19
推荐指数
2
解决办法
3万
查看次数

标签 统计

beta ×1

next-auth ×1

next.js13 ×1

prisma ×1

session ×1