Skip to content

Commit

Permalink
fix: Do not error in authentication client on logout (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jul 20, 2019
1 parent e935df9 commit 8211b98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/authentication-client/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,20 @@ export class AuthenticationClient {

logout () {
return Promise.resolve(this.app.get('authentication'))
.then(() => this.service.remove(null))
.then((authResult: AuthenticationResult) => this.removeAccessToken()
.then(() => this.reset())
.then(() => {
this.app.emit('logout', authResult);

return authResult;
})
);
.then(auth => {
if (!auth) {
return null;
}

return this.service.remove(null)
.then((authResult: AuthenticationResult) => this.removeAccessToken()
.then(() => this.reset())
.then(() => {
this.app.emit('logout', authResult);

return authResult;
})
);
});
}
}
10 changes: 10 additions & 0 deletions packages/authentication-client/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ describe('@feathersjs/authentication-client', () => {
},

remove (id) {
if (!app.get('authentication')) {
throw new Error('Not logged in');
}

return Promise.resolve({ id });
}
});
Expand Down Expand Up @@ -131,6 +135,12 @@ describe('@feathersjs/authentication-client', () => {
});
});

it('logout when not logged in without error', async () => {
const result = await app.logout();

assert.strictEqual(result, null);
});

describe('reauthenticate', () => {
it('fails when no token in storage', () => {
return app.authentication.reAuthenticate().then(() => {
Expand Down

0 comments on commit 8211b98

Please sign in to comment.