feat(#78): allow cookieExpiresAfterDays as a function#79
feat(#78): allow cookieExpiresAfterDays as a function#79gtnsimon wants to merge 3 commits intoboscop-fr:mainfrom
Conversation
This allow to conditionally define expiration days of cookie based on user consent.
| ? configCookieExpiresAfterDays(this.consents, this.config) | ||
| : configCookieExpiresAfterDays; | ||
|
|
||
| if ( |
There was a problem hiding this comment.
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.
cookieExpiresAfterDays could then be a const var.
There was a problem hiding this comment.
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.
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