Skip to content

Commit

Permalink
Merge pull request #50 from videsk/develop
Browse files Browse the repository at this point in the history
fix(storage): initialization storage fixed
  • Loading branch information
matiaslopezd authored May 18, 2022
2 parents 68db158 + b0ed6f7 commit 94067c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
14 changes: 11 additions & 3 deletions .idea/workspace.xml

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

2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WebAuth {
* @returns {Promise<String|undefined>}
*/
login(accessToken, refreshToken, remember = false) {
this.storage = remember ? 'localStorage' : 'sessionStorage';
return this.set(accessToken, refreshToken, remember, true);
}

Expand All @@ -62,7 +63,6 @@ class WebAuth {
* @returns {Promise<String|undefined>}
*/
async set(access = '', refresh = '', remember = false, forceNew = false) {
this.storage = remember ? 'localStorage' : 'sessionStorage';
const { accessToken = access, refreshToken = refresh } = !forceNew ? this.getTokens() : { accessToken: access, refreshToken: refresh };
this.debug('log', 'Initializing WebAuth with tokens', accessToken, refreshToken);
if (!accessToken) return this.fire('empty', accessToken);
Expand Down
18 changes: 9 additions & 9 deletions test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Test WebAuth', function () {
const auth = new WebAuth(randomKeys());
const { accessToken: keyAccess, refreshToken: keyRefresh } = auth.keys;
auth.on('verify', () => true);
await auth.set(accessToken, refreshToken, true);
await auth.login(accessToken, refreshToken, true);
chai.expect(window.localStorage.getItem(keyAccess)).to.be.equal(accessToken);
chai.expect(window.localStorage.getItem(keyRefresh)).to.be.equal(refreshToken);
});
Expand All @@ -176,7 +176,7 @@ describe('Test WebAuth', function () {
chai.expect(checkStoreIsEmpty(key, key2)).to.be.equal(true);
resolve();
});
await auth.set(accessToken, refreshToken);
await auth.login(accessToken, refreshToken);
auth.logout();
});
});
Expand All @@ -188,7 +188,7 @@ describe('Test WebAuth', function () {
auth.on('verify', () => true);
return new Promise(resolve => {
auth.on('ready', resolve);
auth.set(accessToken, refreshToken);
auth.login(accessToken, refreshToken);
});
});

Expand All @@ -200,7 +200,7 @@ describe('Test WebAuth', function () {
return new Promise(async resolve => {
await wait();
auth.on('ready', resolve);
return auth.set(accessToken, refreshToken);
return auth.login(accessToken, refreshToken);
});
}).timeout(5000);

Expand All @@ -217,7 +217,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
await auth.set(accessToken, refreshToken);
await auth.login(accessToken, refreshToken);
});
}).timeout(10000);

Expand All @@ -234,7 +234,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
await auth.set(accessToken, refreshToken);
await auth.login(accessToken, refreshToken);
});
}).timeout(5000);

Expand All @@ -258,7 +258,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
await auth.set(accessToken, refreshToken);
await auth.login(accessToken, refreshToken);
});
}).timeout(15000);

Expand All @@ -279,7 +279,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
await auth.set(accessToken, refreshToken);
await auth.login(accessToken, refreshToken);
await auth.renew();
});
});
Expand All @@ -302,7 +302,7 @@ describe('Test WebAuth', function () {
await wait(3000);
const login2 = await login();
auth.on('ready', resolve);
await auth.set(login2.accessToken, login2.refreshToken);
await auth.login(login2.accessToken, login2.refreshToken);
});
}).timeout(5000);

Expand Down

0 comments on commit 94067c6

Please sign in to comment.