Cookie 未设置
我正在尝试使用 npm cookies-package 设置 cookie
,但不知何故,cookie
未正确设置。
解析器有一个login
方法:
login: async (parent: any, args: any, context: any) => {
const { req, res } = context
const { loginInput } = args
const { email, password } = loginInput
const user = await prisma.user.findUnique({
where: { email }
})
if (user && (await compare(password, user.password))) {
const secret = process.env.SECRET
const token = secret ? sign({ id: user.id }, secret) : null
if (token) {
const cookies = new Cookies(req, res)
cookies.set('token', token)
return true
}
}
return false
}
I am trying to set a cookie
with the npm cookies-package, but somehow the cookie
does not get set properly.
The resolver has a login
method:
login: async (parent: any, args: any, context: any) => {
const { req, res } = context
const { loginInput } = args
const { email, password } = loginInput
const user = await prisma.user.findUnique({
where: { email }
})
if (user && (await compare(password, user.password))) {
const secret = process.env.SECRET
const token = secret ? sign({ id: user.id }, secret) : null
if (token) {
const cookies = new Cookies(req, res)
cookies.set('token', token)
return true
}
}
return false
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论