So basically I use getServerSideProps to call some APIs. when I call getSession in getServerSideProps() I get a valid object.
export async function getServerSideProps({ req }) {
const session = await getSession({ req }); // works
But when I call it in the API that is called in that getServerSideProps() function, I get null.
import { getSession } from "next-auth/react";
export default async (req, res) => {
const { db } = await connectToDatabase();
const session = await getSession({ req }); // returns null
Here is NextAuth documentation for reference: