小编Ant*_*nio的帖子

Next Auth getSession 在 api 路由中不起作用

所以基本上我使用 getServerSideProps 来调用一些 API。当我在 getServerSideProps() 中调用 getSession 时,我得到一个有效的对象。

export async function getServerSideProps({ req }) {
   const session = await getSession({ req }); // works
Run Code Online (Sandbox Code Playgroud)

但是当我在 getServerSideProps() 函数中调用的 API 中调用它时,我得到 null。

import { getSession } from "next-auth/react";

export default async (req, res) => {
  const { db } = await connectToDatabase();

  const session = await getSession({ req }); // returns null
Run Code Online (Sandbox Code Playgroud)

这是 NextAuth 文档供参考:

在此输入图像描述

api reactjs next.js next-auth

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

api ×1

next-auth ×1

next.js ×1

reactjs ×1