skip to Main Content
//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

2

Answers


  1. Chosen as BEST ANSWER

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

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

  2. 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),
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search