-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat(#78): allow cookieExpiresAfterDays as a function #79
base: master
Are you sure you want to change the base?
feat(#78): allow cookieExpiresAfterDays as a function #79
Conversation
This allow to conditionally define expiration days of cookie based on user consent.
src/consent-manager.js
Outdated
? configCookieExpiresAfterDays(this.consents, this.config) | ||
: configCookieExpiresAfterDays; | ||
|
||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe remove this test and use a default value in setCookie
like before.
This way any falsy or 0 value would be set to the default.
setCookie(
this.cookieName,
value,
cookieExpiresAfterDays || 120,
this.config.cookieDomain
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cookieExpiresAfterDays
could then be a const
var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with falsies values but 0
as an integer has a meaning for cookie expiration which ends when browser is closed. Using cookieExpiresAfterDays || 120
will replace 0
to 120
which may not be the expected behavior by the end developer.
To not break existing installations, the default could apply to non-functional cookieExpiresAfterDays
(like before this feature). When used as a function it'll be up to the developer to explicitly return a value if he don't want a session cookie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about this behavior with 0, given the old implementation I thought it was kind of invalid.
I'm kind of torn here, it would be a breaking change to modify the current behavior, but it seems odd to have different behaviors for different methods...
This will prevent replacing a `return 0` from developer code land with the default `120` from orejime.
This allow to conditionally define cookie duration based on user consent.
Here a snippet function to control cookie duration using a function:
Resolves: #78