0
//creation of token 
res.cookie('jwt', token, { httpOnly: true, maxAge : 60 * 60 * 24});
// the logout and where i want to destroy it
 exports.logout = (req, res) => {
    res.cookie('jwt', "token", {httpOnly:true,maxAge:1000})
    // res.clearCookie('jwt');
}

it can't be destroyed after the logout function

  • Does this answer your question? [How to destroy JWT Tokens on logout?](https://stackoverflow.com/questions/37959945/how-to-destroy-jwt-tokens-on-logout) – Moshe Fortgang Apr 25 '23 at 10:35

2 Answers2

0

You need to set an expiry date in the past, similar to this. Browsers will then discard the cookie and stop sending it. If applicable use the same cookie domain and path that you used when creating the cookie.

res.cookie('jwt', "", {
    httpOnly: true, 
    expires: new Date(Date.now() - 86400),
})
Gary Archer
  • 22,534
  • 2
  • 12
  • 24
0

i tried this by changing the value and the expiration time :

res.clearCookie('jwt', {httpOnly:true,maxAge:1, value: "token"})