I am trying to delete a cookie using the js-cookie library.
Note that this cookie is not created by me. Is by another team and
can't be changing this cookie in any manner.
But the cookie remains even after attempting to delete.
Could I please know what I am doing wrong?
These are the details of the cookie.
name: my_cookie
value: uligasdf67gdjfkb
Domain: .mycompany.com
Path: /
Expires / Max-Age: 2021-09-15T21:39:37:757Z
Size 59
HttpOnly: Has a tick which I believe indicates yes.
SameSite: Lax
SameParty: (Empty)
Priority: Medium
This cookie is set to expire in 10 minutes after being set but depending on certain logic, I want to just delete it before the expiry.
This is how I am trying to delete it which no effect, cookie not deleted.
Using js-cookie package.
Importing in my package.json file
"dependencies": {
"js-cookie": "^2.2.0"
},
Logic to delete.
import Cookies from 'js-cookie';
Cookies.remove('my_cookie', { path: '/', domain: '.mycompany.com' });
Is there a way around this to delete it?
Edit:
Tried what is suggested in this page to set cookie with empty value to essentially delete cookie.
Cookies.set('my_cookie', '');
But I end up with 2 cookies. The difference being the domain.
The existing cookie which is still not deleted.
name value domain
my_cookie asdfasdfasfd .mycompany.com
Cookie getting duplicated instead of overriding
name value domain
my_cookie qwww.mycompany.com