cookies-next
cookies-next copied to clipboard
Delete cookie is not deleting the cookie
I am using the lib to create cookies with some key - for example "user" when i use the same key to delete the cookie nothing gets deleted.
When and where do you try to delete the cookie? Please, I'd like to see the code
deleteCookie('_token_', { path: '/profile', domain: 'localhost:3000' });
not working as well as the set cookie not working with same options
It's not working for me as well. It actually works on my localhost but not on my staging environment
I had the same issue as @victorpotasso - on localhost the cookie got deleted but in deployed instance (staging) it did not. Figured out that the problem was not setting domain
in deleteCookie
to the same value that was passed in setCookie
options. There's actually even a note in libraries docs which helped me to solve this -
"IMPORTANT! When deleting a cookie and you're not relying on the default attributes, you must pass the exact same path and domain attributes that were used to set the cookie:".
So in the end the call looked like this: deleteCookie('promo', { req, res, domain })
(I believe req
and res
are needed for SSR usage).
Sharing this in case you missed this part same as I did 🙌