Skip to content

Commit

Permalink
handle cookie storage
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Jan 14, 2022
1 parent cd70997 commit 286371a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/browser/browserStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,15 @@ var storageUtil: BrowserStorageUtil = {
const storage: CookieStorage = {
getItem: function(key) {
const value = storageUtil.storage.get(key);
try {
// return object
return JSON.parse(value);
} catch (e) {
// ignore parse error
// return string value
return value;
// returns object that contains all cookies when no key is provided
if (!key) {
try {
return JSON.parse(value);
} catch (e) {
// do nothing
}
}
return value;
},
setItem: function(key, value, expiresAt = '2200-01-01T00:00:00.000Z') {
// By defauilt, cookie shouldn't expire
Expand Down Expand Up @@ -256,8 +257,7 @@ var storageUtil: BrowserStorageUtil = {
get: function(name: string): string {
// get all cookies
if (typeof name === 'undefined') {
// js-cookie returns object when no argument is provided
const value = Cookies.get();
const value = Cookies.get(); // no arguments returns all cookies in object
return JSON.stringify(value);
}
// get cookie by name
Expand Down
2 changes: 1 addition & 1 deletion test/spec/TokenManager/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe('TokenManager (browser)', function() {
return client.tokenManager.get('test-idToken')
.then(function(token) {
expect(token).toEqual(tokens.standardIdTokenParsed);
expect(getCookieMock).toHaveBeenCalledWith();
expect(getCookieMock).toHaveBeenCalledWith(undefined);
expect(setCookieMock).not.toHaveBeenCalled();
});
});
Expand Down

0 comments on commit 286371a

Please sign in to comment.