Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ var orejimeConfig = {
// defaults to "orejime".
cookieName: "orejime",

// Optional. You can set a custom expiration time for the Orejime cookie, in days.
// Optional. You can set a custom expiration time for the Orejime cookie, in days,
// by using an integer or a function returning an integer.
// The function has the following signature: `function cookieExpiresAfterDays (consents, config): integer`
// - consents is an object of apps name defined in `config.apps[].name` with their consent value as a boolean (same as the cookie value).
// - config is your defined configuration (this object).
// You can find a snippet function here: https://github.com/empreinte-digitale/orejime/pull/79#issue-1100817288
// defaults to 365.
cookieExpiresAfterDays: 365,

Expand Down
8 changes: 7 additions & 1 deletion src/consent-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,17 @@ export default class ConsentManager {
saveConsents() {
if (this.consents === null) deleteCookie(this.cookieName);
const value = this.config.stringifyCookie(this.consents);
const configCookieExpiresAfterDays = this.config.cookieExpiresAfterDays;

const cookieExpiresAfterDays =
typeof configCookieExpiresAfterDays === 'function'
? configCookieExpiresAfterDays(this.consents, this.config)
: configCookieExpiresAfterDays || 120;

setCookie(
this.cookieName,
value,
this.config.cookieExpiresAfterDays || 120,
cookieExpiresAfterDays,
this.config.cookieDomain
);
Comment thread
felixgirault marked this conversation as resolved.

Expand Down