【发布时间】:2021-03-30 13:53:49
【问题描述】:
我正在尝试在客户端浏览器上设置删除包含 JWT 的 cookie 的路由。
为此,我使用 res.ClearCookie 函数
public async logOut (req: Request, res: Response) {
res.clearCookie('auth-token', {httpOnly: true, path:'/', domain: 'localhost'});
console.log('cookie deleted')
}
我看到 clearCookie 函数必须包含我在创建它时传递的相同对象,所以这是我创建它的方式
const accessToken: string = jwt.sign({id: existingUser.id}, process.env.ACCESS_TOKEN_SECRET || 'tokensecret' )
return res.cookie('auth-token', accessToken, {httpOnly: true, path:'/', domain: 'localhost'}).json(mainWallet[0].id)
这样,当我尝试注销时,cookie 不会被删除。
你有解决这个问题的想法吗?
谢谢,
保罗
【问题讨论】:
-
嘿@Anatoly,感谢您的回复。可悲的是,在我的情况下,其他线程中建议的解决方案都不起作用......
标签: node.js typescript jwt