Skip to content

Commit cf32149

Browse files
authored
Merge pull request #167 from moneytree/link-4184-localstorage-cv
[LINK-4184] Store `code_verifier` in `localStorage`
2 parents 16398e9 + 32e8fbf commit cf32149

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/__tests__/storage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ describe('storage', () => {
1010
});
1111

1212
test('get with invalid existing storage value', () => {
13-
window.sessionStorage.setItem(STORE_KEY, '"abc"');
13+
window.localStorage.setItem(STORE_KEY, '"abc"');
1414

1515
expect(get('key1')).toBeUndefined();
1616

17-
window.sessionStorage.setItem(STORE_KEY, '');
17+
window.localStorage.setItem(STORE_KEY, '');
1818

1919
expect(get('key1')).toBeUndefined();
2020
});

src/api/exchange-token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default async function exchangeToken(
6464
throw new Error(result.error_description);
6565
}
6666

67+
storage.del('cv');
6768
return result as Token;
6869
} catch (error) {
6970
throw new Error(`[mt-link-sdk] \`exchangeToken\` execution failed. ${error}`);

src/storage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export const STORE_KEY = 'mt-link-javascript-sdk';
22

3-
const sessionStorage = window.sessionStorage;
3+
const localStorage = window.localStorage;
44

55
function getStorageObject(): { [key: string]: string } {
6-
const stringifiedData = sessionStorage.getItem(STORE_KEY) || '';
6+
const stringifiedData = localStorage.getItem(STORE_KEY) || '';
77
let data = {};
88

99
try {
@@ -23,14 +23,14 @@ export function set(key: string, value: string): void {
2323
const data = getStorageObject();
2424
data[key] = value;
2525

26-
sessionStorage.setItem(STORE_KEY, JSON.stringify(data));
26+
localStorage.setItem(STORE_KEY, JSON.stringify(data));
2727
}
2828

2929
export function del(key: string): void {
3030
const data = getStorageObject();
3131
delete data[key];
3232

33-
sessionStorage.setItem(STORE_KEY, JSON.stringify(data));
33+
localStorage.setItem(STORE_KEY, JSON.stringify(data));
3434
}
3535

3636
export default {

0 commit comments

Comments
 (0)