Access token cookie is not replaced!
sb-andy opened this issue · 4 comments
Hello,
I have a problem:
const cookies = new Cookies();
- I set initial cookie like this: cookies.set("accessToken", initialAccessToken, { secure: true, });
- After generating a new access token I use the same: cookies.set("accessToken", newAccessToken, { secure: true, });
The problem is: it duplicates. I can see 2 cookies "accessToken". What do I do wrong? Thank you in advance.
iam facing the same problem when i refresh the page for some reason the cookies duplicates, and when try to using remove('cookie') the target cookie not removed from the browser. but when i refresh the browser the target cookie that intent to remove, duplicates.
i am using vue 3
i think i know what's causing this. if you are using Ventura 13.1 (as i am), i think this bug appears because of this. i try in different OS (win 11) and it runs as it should no problem at all
I'm having this issue as well. It does it using universal-cookie or react-cookies
Seems to have to do with the path option when a cookie is set. When you call setCookie()
, the cookie will be set with the current path. If you try to set the same cookie at a different path, it will create a duplicate.
I solved this for myself by setting the path option in setCookie
to be /
.
e.g.
setCookie('team', teamId, { path: '/' });
It would be nice to have an option on the cookie provider to set a default path instead of taking the current path.
Edit:
I realize this is mentioned in the docs but I completely glossed over it myself.
https://github.com/reactivestack/cookies/tree/master/packages/react-cookie#setcookiename-value-options
@AllenWilliamson I agree it would be nice. A default set options will be added in v6.