在 gql 上下文中获取下一个身份验证用户会话时遇到问题

Having trouble getting next-auth user session in gql context

这个post中提供的答案对我不起作用,也没有更新。 Getting NextAuth.js user session in Apollo Server context

// ./graphql/context.ts
/**
 * Populates a context object for use in resolvers.
 * If there is a valid session from next-auth, find the user and add them to context
 * @param context context from apollo server
 */
type ApolloApiContext = ApolloContext < {
  req: IncomingMessage
} > ;
export async function createContext(context: ApolloApiContext): Promise < Context > {
  const session = await getSession(context); // ALWAYS null
  let user: User | null = null;
  if (session?.user?.email) {
    user = await prisma.user.findUnique({ where: { email: session.user.email } });
   }
  return {
    db: prisma,
    prisma,
    user,
  };
}

我猜 Next v Apollo 对请求的期望不匹配。对如何将有效的下一个身份验证会话进入 gql 上下文有任何想法吗?

const session = await getSession({ req: context.req });