graphql-passport
graphql-passport copied to clipboard
empty context.getUser() when made a request from react. (it works in playground)
Hello.
I am trying to login and update a collection.
This is my context creation:
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req, res }) => {
return buildContext({ req, res, User })
},
playground: {
settings: {
'request.credentials': 'same-origin',
},
},
});
I have here a console log who perfectly made the validation and can log out the current user in the context:
console.log('💃 ', context.req.user)
Later on, in my secure middleware i am hable to get the context for future request:
if (!context.getUser()) throw new AuthenticationError('Unauthenticated')
const {id, rol} = context.getUser();
Now, my problem is when I try to do all this from my react app , because all this works fine from the playground.
Because now, the context is complete lost, and i am not able to pass my secure middleware.
where is my issue? in my react or express app??
This is most likely an issue due to the credentials not being sent from the react app. Try changing https://github.com/josuevalrob/CLE/blob/master/src/services/apolloClient.js#L23 to "include"