Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/amazon-cognito-identity-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ The CookieStorage object receives a map (data) in its constructor that may have
- data.path Cookies path (default: '/')
- data.expires Cookie expiration (in days, default: 365)
- data.secure Cookie secure flag (default: true)
- data.sameSite Cookie request behaviour (default: null)

**Use case 27.** Selecting the MFA method and authenticating using TOTP.

Expand Down
1 change: 1 addition & 0 deletions packages/amazon-cognito-identity-js/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/amazon-cognito-identity-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"buffer": "4.9.1",
"crypto-js": "^3.3.0",
"js-cookie": "^2.1.4"
"js-cookie": "^2.2.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a note that SameSite was added in:

js-cookie/js-cookie#276 (comment)

},
"devDependencies": {
"@babel/cli": "^7.7.4",
Expand Down
32 changes: 28 additions & 4 deletions packages/amazon-cognito-identity-js/src/CookieStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class CookieStorage {
* @param {string} data.path Cookies path (default: '/')
* @param {integer} data.expires Cookie expiration (in days, default: 365)
* @param {boolean} data.secure Cookie secure flag (default: true)
* @param {string} data.sameSite Cookie request behaviour (default: null)
*/
constructor(data) {
if (data.domain) {
Expand All @@ -31,6 +32,16 @@ export default class CookieStorage {
} else {
this.secure = true;
}
if (Object.prototype.hasOwnProperty.call(data, 'sameSite')) {
if (data.sameSite !== 'strict' && data.sameSite !== 'lax') {
throw new Error(
'The sameSite value of cookieStorage must be "lax" or "strict".'
);
}
this.sameSite = data.sameSite;
} else {
this.sameSite = null;
}
}

/**
Expand All @@ -40,12 +51,18 @@ export default class CookieStorage {
* @returns {string} value that was set
*/
setItem(key, value) {
Cookies.set(key, value, {
const options = {
path: this.path,
expires: this.expires,
domain: this.domain,
secure: this.secure,
});
};

if (this.sameSite) {
options.sameSite = this.sameSite;
}

Cookies.set(key, value, options);
return Cookies.get(key);
}

Expand All @@ -65,11 +82,18 @@ export default class CookieStorage {
* @returns {string} value - value that was deleted
*/
removeItem(key) {
return Cookies.remove(key, {
const options = {
path: this.path,
expires: this.expires,
domain: this.domain,
secure: this.secure,
});
};

if (this.sameSite) {
options.sameSite = this.sameSite;
}

return Cookies.remove(key, options);
}

/**
Expand Down