Skip to content

Commit

Permalink
Fix cookie.set option defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Sep 18, 2023
1 parent 22d8ce0 commit 2db49a3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/nationalarchives/lib/cookies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export default class Cookies {
return decodeURIComponent(this.all[key]);
}

set(key, value, options) {
const { maxAge, path, sameSite } = options;
set(key, value, options = {}) {
const {
maxAge = 60 * 60 * 24 * 365,
path = "/",
sameSite = "Lax",
} = options;
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(
value,
)}; SameSite=${sameSite || "Lax"}; path=${path || "/"}; max-age=${
maxAge || 60 * 60 * 24 * 365
}; Secure`;
)}; SameSite=${sameSite}; path=${path}; max-age=${maxAge}; Secure`;
this.#getPolicies();
}

Expand All @@ -62,7 +64,7 @@ export default class Cookies {
}

get allPolicies() {
return JSON.parse(this.get(this.cookiesPolicyKey));
return JSON.parse(this.get(this.cookiesPolicyKey) || "{}");
}

policy(policy) {
Expand Down

0 comments on commit 2db49a3

Please sign in to comment.