我正在尝试设置一条在客户端浏览器上删除包含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不会被删除。
你有什么办法解决这个问题吗?
谢谢,
保罗
发布于 2020-12-21 17:18:11
我遵循了一个新的教程,它告诉我要这样设置注销路线。这一次它成功了
res.status(202).clearCookie('auth-token').send('cookie cleared')发布于 2020-12-26 23:01:59
使用这些代码集来构造您的Api。这是我找到的最干净、最短的注销记录
export const logout = async (req, res, next) => {
res.clearCookie("jwt");
res.redirect("/");
};此操作仅清除存储在cookie中的令牌
https://stackoverflow.com/questions/65381965
复制相似问题