Skip to content

Commit

Permalink
fix(clean): fixed key name for delete from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaslopezd committed Apr 7, 2022
1 parent c21afd5 commit 0d811a4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 14 additions & 4 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 @@ -120,7 +120,7 @@ class WebAuth {
*/
clean() {
this.debug('log', 'Cleaning store...');
const keys = Object.keys(this.keys);
const keys = Object.values(this.keys);
keys.forEach(key => {
window.localStorage.removeItem(key);
window.sessionStorage.removeItem(key);
Expand Down
13 changes: 13 additions & 0 deletions test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ describe('Test WebAuth', function () {
});
});

it('Login, set accessToken and refreshToken, then clean storage', async function () {
const response = await chai.request(hostname).get('/login');
const { accessToken, refreshToken } = response.body;
const auth = new WebAuth(randomKeys());
auth.on('verify', () => true);
await auth.set(accessToken, refreshToken);
auth.logout();
chai.expect(window.localStorage.getItem(auth.keys.accessToken)).to.be.equal(undefined);
chai.expect(window.sessionStorage.getItem(auth.keys.accessToken)).to.be.equal(undefined);
chai.expect(window.localStorage.getItem(auth.keys.refreshToken)).to.be.equal(undefined);
chai.expect(window.sessionStorage.getItem(auth.keys.refreshToken)).to.be.equal(undefined);
});

it('Login and set accessToken and refreshToken, then check is in sessionStorage', async function () {
const response = await chai.request(hostname).get('/login');
const { accessToken, refreshToken } = response.body;
Expand Down

0 comments on commit 0d811a4

Please sign in to comment.