I couldn't get req.cookies
, even req.headers
as it return empty object and undefined.
I tried 'request.credentials'
value with include
and same-origin
, both not working.
I can get req.cookies
from getServerSideProps
but I don't want do this on every pages or create a HOF for this.
So, the question is why req.cookies
in context
is empty object?
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'
})
);