Reputation: 655
I'm trying to initialize cookie on login using express-session but it only seem to be working am requesting from same site.
Apollo-Client:
const endPoint = createUploadLink({
uri: 'http://localhost:4000/graphql'
})
const client = new ApolloClient({
link: endPoint,
credentials: 'include',
cache: new InMemoryCache(),
})
Apollo-server:
const corsOptions = {
origin: "http://localhost:3000",
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization']
}
app.use(session({
name: 'foo',
secret: 'bar',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 360000,
sameSite: 'none',
httpOnly: true
}
}))
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
playground: {
settings: {
'request.credentials': 'include'
}
},
cors: corsOptions
});
Now if request is made via graphql playground the cookies is set but if login request is made from localhost:3000 and session initialized no cookie is set.
Please am I missing here.
Upvotes: 0
Views: 1800
Reputation: 1
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache,
fetchOptions: {
credentials: "include",
}
})
its working for me ...try this
Upvotes: 0