cookies-next icon indicating copy to clipboard operation
cookies-next copied to clipboard

Delete cookie is not deleting the cookie

Open TomerLankri opened this issue 1 year ago • 4 comments

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.

TomerLankri avatar Jan 28 '24 20:01 TomerLankri

When and where do you try to delete the cookie? Please, I'd like to see the code

andreizanik avatar Feb 03 '24 16:02 andreizanik

deleteCookie('_token_', { path: '/profile', domain: 'localhost:3000' });

not working as well as the set cookie not working with same options

riazahmadshigri avatar Feb 20 '24 17:02 riazahmadshigri

It's not working for me as well. It actually works on my localhost but not on my staging environment

victorpotasso avatar Mar 26 '24 02:03 victorpotasso

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 🙌

justenau avatar Apr 09 '24 11:04 justenau