javascriptexpresscookies

Impossible to delete 2 cookies at the same time


I have 2 cookies named : access_token and refresh_token.

I can't delete these 2 cookies at the same time by:

const logout = (req, res) => { 
    res.clearCookie('access_token', { path: '/' });
    res.clearCookie('refresh_token', { path: '/' });
    return res.status(200).json({
        EM: "logout success",
        EC: 1,
        DT: "",
    });
}

But when I only have 1 cookie, I can still clear it by using clearCookie() method.

I want to delete all cookies in 1 action.

How can I do it? or any suggest please!! Thanks.


Solution

  • You are passing the path as option to clearCookie but you are probably missing some other options your cookies have so they are not identical. Make sure to pass all the options you’ve set for your cookies. (E.g. Domain, sameSite,…)