Comments (7)
Hey, @justinaray we have maxAge option, which takes a time in seconds, so I've documented that on the Readme. Does that work as an alternative to overloading expires?
from ember-cookies.
I'm not sure this is something that's actually needed to be honest, especially as we'd just be adding shortcuts that's already very simple, e.g. For 3 days:
3 * 24 * 60 * 60
Also if you treat expires: 3
as 3 days how would you distinguish that from a 3 second expiry?
from ember-cookies.
Completely agree that it's trivial, but you do have to pass a Date instance for expires
, right? So it's a bit more involved.
this.get('cookies').write(MY_COOKIE_NAME, cookieVal, {
...
expires: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000) // Raw Date approach
expires: moment().add(3, 'days').toDate() // Moment approach
...
}
Again, this is pretty straightforward to write, but I saw it and immediately thought of a utility so I suggested it. To me, this seems easier:
this.get('cookies').write(MY_COOKIE_NAME, cookieVal, {
...
expires: '3d' // 3 days
...
}
Completely up to you as a maintainer, but just thought I'd suggest it. Thanks again for the addon!
Re: Number param
I also agree that a Number value for expires
is ambiguous. I just suggested days as a default as it's consistent with the other cookie libraries. I guess they assume standard cookie duration is in days? Had I designed the api for those other libraries, I would have probably supported a String variant with value/units as I suggested above.
from ember-cookies.
but you do have to pass a Date instance for expires, right?
Good point ;) I guess allowing to pass a number (and treating this as "seconds from now") would actually be a good idea then.
I'd actually not want to allow strings like '3d'
- if we allow passing seconds I think there's very little need for something like this and we'd add a custom vocabulary that mostly adds unnecessary complexity to the library. The main idea behind ember-cookies is to provide a cooke abstraction that works both in the browser as well as on the server and not really to provide a fancy API on top of cookies.
from ember-cookies.
Seconds seems like a good and flexible default to me! Easy to do the maths from there as you initially commented.
Would you prefer to overload expires
as we've been chatting about or add another option key for the seconds config?
I am pretty swamped with work as I am sure you are as well. Just wanted to hash out the api in case I find some time this weekend to look into a PR.
Aside (Again working through the API)
Millis are usually the standard time manipulation unit, but since cookies only have second precision, I think that's perfectly fine to use seconds as the default here and not to go to that level of precision in this API.
from ember-cookies.
Would you prefer to overload expires as we've been chatting about or add another option key for the seconds config?
I think overloading should be fine.
Millis are usually the standard time manipulation unit, but since cookies only have second precision, I think that's perfectly fine to use seconds as the default here and not to go to that level of precision in this API.
max-age
is in seconds as well (see https://developer.mozilla.org/en-US/docs/Web/API/document/cookie) so I think seconds should be fine.
from ember-cookies.
Thanks @geekygrappler and @marcoow. Max-Age
will work for our use case, seems to have pretty good browser support, and MDN says it will be preferred over Expires
if both are set and supported.
👍
from ember-cookies.
Related Issues (20)
- Expire On Cookie HOT 1
- DEPRECATION: Use of `merge` has been deprecated HOT 2
- An in-range update of ember-cli-babel is breaking the build 🚨 HOT 3
- Fastboot causes double decoding HOT 2
- Addon causes linked apps to error during build. "Babel loaded v6.x.x" HOT 1
- npm deploy build step failed HOT 2
- `Cannot read property 'split' of undefined` error in tests when upgrading to ember 3.13.0 HOT 1
- [0.5.1 Regression] TypeError: Cannot read property 'isFastBoot' of undefined HOT 1
- Add SameSite=None support (and UA check?) HOT 3
- nodetest task HOT 1
- Setting max age in FastBoot
- Add a timeout to CI GitHub workflow for test step
- cookies not working
- Dependency Dashboard
- Cut new release HOT 3
- Convert addon to V2 HOT 2
- TypeError: can't access dead object HOT 2
- Ember v5 - current ember-canary, ember-beta channels are failing under fastboot HOT 1
- [Embroider] Fails under fastboot in embroider-optimized scenario
- Action Required: Fix Renovate Configuration
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 ember-cookies.