我无法得到req.cookies
,即使req.headers
它返回空对象且未定义。
我用and尝试'request.credentials'
了 value ,但都不起作用。include
same-origin
我可以从中获得req.cookies
,getServerSideProps
但我不想在每个页面上都这样做或为此创建一个 HOF。
那么,问题是为什么req.cookies
incontext
是空对象?
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'
})
);