Skip to content

Commit

Permalink
fix(authentication-client): Properly handle missing token error (#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jul 19, 2022
1 parent 1f71d78 commit 160746e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/authentication-client/src/core.ts
Expand Up @@ -145,7 +145,7 @@ export class AuthenticationClient {
if (!authPromise || force === true) {
authPromise = this.getAccessToken().then((accessToken) => {
if (!accessToken) {
throw new NotAuthenticated('No accessToken found in storage')
return this.handleError(new NotAuthenticated('No accessToken found in storage'), 'authenticate')
}

return this.authenticate({
Expand Down
3 changes: 2 additions & 1 deletion packages/authentication-client/test/index.test.ts
Expand Up @@ -154,10 +154,11 @@ describe('@feathersjs/authentication-client', () => {
})

describe('reauthenticate', () => {
it('fails when no token in storage', async () => {
it('fails when no token in storage and resets authentication state', async () => {
await assert.rejects(() => app.authentication.reAuthenticate(), {
message: 'No accessToken found in storage'
})
assert.ok(!app.get('authentication'), 'Reset authentication')
})

it('reauthenticates when token is in storage', async () => {
Expand Down

0 comments on commit 160746e

Please sign in to comment.