New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useCookie
with maxAge
or expires
gets removed when updated
#24227
Comments
@ChrisGV04 I'm facing the same issue |
Hi @RomanSkrypnik! I see you had a similar issue, however in my case I'm not even using If that's the expected behavior, I don't understand how should cookies with options be updated. I did as the docs show and just added options. It makes And yeah, that's a breaking change! I didn't notice until a customer told me that every time they enter or refresh my website they keep getting the cookie consent even after accepting... |
Hi everyone! Pr #23697 seems to be related to this issue. |
Hi, We had a similar issue. The code is trying to convert maxAge to milliseconds to use setTimeout. But it looks like the value is too big. Our workaround would be to decrease maxAge to less than 20 days, but waiting for a more robust solution. Maximum delay value |
Is there a solution to the problem? |
Hi @positiveprogrammer! I went through the code for the The I think I have an idea on how to solve it or at least to work around it since it's a browser limitation. I will work on a PR for it |
Hello, I'm also facing the same issue. 1 to 24 days work but 25 days do not. However, if I set it to 1 year it works
Nuxt Version: 3.8.1 |
cookie is using miliseconds, should do 365 * 24 * 60 * 60 * 1000 |
Hi @junkiet! |
What I test just now, maxAge: -1 at setCookie() at server side at client side, need to set also but using useCookie(): I have no idea, why need to set both server and client side, is it something depreciated at 3.8.1 or a bug? |
Hi @junkiet I wrote about this issue and why it's happening in detail at my currently open PR #24253. The issue only exists on the client side, that's why if you set the cookie on the server, it always works. In the client it uses |
ii see, I will try it |
I found the problem, once execute deleteCookie, whever you set in setcookie, it will be automatically set to expiry immediately, so I use normal and simple way auth.value = null to delete it, then work as normal., before 3.7 nuxt, deleteCookie is working fine |
Environment
Reproduction
I used the starter project from
pnpx nuxi@latest init
and just replaced theapp.vue
with the following code:Describe the bug
When I click the
acceptConsent
button, I set the cookie value fromno
toyes
. However, instead of saving theyes
value inside the cookie, it gets removed completely. I tried on Firefox v119.0.1 and Chrome v119.0.6. Both browsers have the exact same behavior.The strange part is that if I remove the
maxAge
option fromuseCookie
, everything works fine. But I would like that the consent cookie expires after 30 days. I also tried withexpires
and the same issue happened.I'm not sure if I'm doing something wrong or if it really is a bug, but I would expect that if I change the value of the cookie, it must be persisted, but it is getting deleted...
Additional context
I'm trying to create a cookie consent dialog that shows once and if it gets accepted, it doesn't show again for 30 days. My reproduction code is just a bare-bones demo with the minimal code I could reproduce it with. In the real website this functionality is inside a
CookieConsent.vue
component and it is a Modal.cookies.mp4
Logs
No response
The text was updated successfully, but these errors were encountered: