来自 apollo-server-micro 的 req.cookies 返回空对象

Ala*_*ong 8 node.js apollo-server next.js next-auth

我无法得到req.cookies,即使req.headers它返回空对象并且未定义。

我尝试使用'request.credentials'valueincludesame-origin,但都不起作用。

我可以req.cookies从中获取getServerSideProps,但我不想在每个页面上都执行此操作或为此创建 HOF。

那么,问题是为什么req.cookiesincontext是空对象?

import { ApolloServer } from 'apollo-server-micro';
import { getToken } from 'next-auth/jwt'
import Cors from 'micro-cors';

const schema = makeExecutableSchema({
  typeDefs,
  resolvers
});

const server = new ApolloServer({
  schema,
  context: async (ctx) => {
    const token = await getToken({req: ctx.req, secret: process.env.JWT_SECRET})

    return {};
  },
  playground: {
    settings: {
      'request.credentials': 'include'
    }
  },
});

const cors = Cors({
  allowMethods: ['POST', 'OPTIONS']
});

export const config = {
  api: {
    bodyParser: false
  }
};

export default cors(
  server.createHandler({
    path: '/api/graphql'
  })
);
Run Code Online (Sandbox Code Playgroud)