Comments (8)
then it incorrectly sets the cookie - which seems to be redundant. My PR handled this.
You're right, I did it this way because the cookie that is set is invalid and immediately dismissed by the browser (set to expire in 1970), the code is also easier to understand.
I had initially tried with a more sophisticated approach with a filter (I implemented it in the set
method, similar to your code), but I think that always setting it to invalid is more performant because before we had to check if the cookie existed with get
and then set
it. Now we only do set
regardless, without additional logic specific to Frontend and SSR.
Anyway, let me know if it works 🤞
from cookie-universal.
I tested it and it works. Thanks for the release ❤️
from cookie-universal.
I prepared PR which fixes this #128
from cookie-universal.
I don't understand this use case. Why would you set the cookie and remove it in the same request?
from cookie-universal.
At first glance this seems useless. However, when the application is really big and complex, this scenario may happen and thus this use-case is valid.
For example, my scenario is as follows:
- in
nuxtServerInit
, i set cookies includingmyCookie
- in page component there is a bunch of logic with plenty of
$fetch
functions - one of those function is encapsulated in a
try catch
block and if the call fails, we want to remove a cookiemyCookie
from cookie-universal.
You convinced me :). I have pushed an update, can you please check v2.2.0
? Apologies for not using your Pull Request, I wanted to add unit tests and there was an issue with setResponseCookie
which would have run also in client side breaking the app. Let me know if it works.
from cookie-universal.
Thanks! I haven't tested yet but as far as I can see from changes, it lacks validation whether the cookie was set or not.
For example, if this is your nuxtServerInit function:
nuxtServerInit() {
this.$cookies.remove('cookieWhichHasNeverBeenSet')
}
then it incorrectly sets the cookie - which seems to be redundant. My PR handled this.
from cookie-universal.
Awesome!
from cookie-universal.
Related Issues (20)
- Migration to ESM HOT 2
- Can't set cookie on mac os browser HOT 2
- Cookie get is not working after chanhing route in asynd fetch or asyncData HOT 4
- client
- Property 'nodeCookie' does not exist on type 'NuxtCookies' HOT 7
- No cookies received from the server HOT 5
- warnings with nuxt3 HOT 2
- PATH not working HOT 2
- cookie.remove should not throw when the cookie is not found HOT 1
- removeAll typing is wrong HOT 1
- Get deleted cookies in duplicate tab
- Cookies disappear HOT 1
- o.set-cookie.map is not a function
- missing license information
- Add cookie-universal-nuxt to nuxt.config.ts HOT 12
- Support top-level options
- remove in middleware not work HOT 3
- remove cookies from client works inconsistency HOT 1
- ERROR Cannot set headers after they are sent to the client
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cookie-universal.