diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7b51b34..db19f74 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -8,7 +8,6 @@
-
@@ -233,7 +232,9 @@
-
+
+
+
1614872764649
@@ -403,7 +404,14 @@
1649357895413
-
+
+ 1650590876456
+
+
+
+ 1650590876456
+
+
diff --git a/src/index.js b/src/index.js
index 252a4b0..e2916fd 100644
--- a/src/index.js
+++ b/src/index.js
@@ -50,6 +50,7 @@ class WebAuth {
* @returns {Promise}
*/
login(accessToken, refreshToken, remember = false) {
+ this.storage = remember ? 'localStorage' : 'sessionStorage';
return this.set(accessToken, refreshToken, remember, true);
}
@@ -62,7 +63,6 @@ class WebAuth {
* @returns {Promise}
*/
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);
diff --git a/test/auth.test.js b/test/auth.test.js
index 65d630b..8448d5a 100644
--- a/test/auth.test.js
+++ b/test/auth.test.js
@@ -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);
});
@@ -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();
});
});
@@ -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);
});
});
@@ -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);
@@ -217,7 +217,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
- await auth.set(accessToken, refreshToken);
+ await auth.login(accessToken, refreshToken);
});
}).timeout(10000);
@@ -234,7 +234,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
- await auth.set(accessToken, refreshToken);
+ await auth.login(accessToken, refreshToken);
});
}).timeout(5000);
@@ -258,7 +258,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
- await auth.set(accessToken, refreshToken);
+ await auth.login(accessToken, refreshToken);
});
}).timeout(15000);
@@ -279,7 +279,7 @@ describe('Test WebAuth', function () {
auth.logout();
resolve();
});
- await auth.set(accessToken, refreshToken);
+ await auth.login(accessToken, refreshToken);
await auth.renew();
});
});
@@ -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);