【发布时间】:2021-07-31 06:47:39
【问题描述】:
我正在尝试使用 express-session 在登录时初始化 cookie,但它似乎只在从同一个站点请求时起作用。
阿波罗客户端:
const endPoint = createUploadLink({
uri: 'http://localhost:4000/graphql'
})
const client = new ApolloClient({
link: endPoint,
credentials: 'include',
cache: new InMemoryCache(),
})
阿波罗服务器:
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
});
现在,如果通过 graphql playground 发出请求,则设置 cookie,但如果从 localhost:3000 发出登录请求并且会话初始化,则不设置 cookie。
请问我在这里失踪了。
【问题讨论】:
标签: reactjs cookies apollo-client apollo-server express-session