From 160746e2bceb465fd1b6a003415f8ab38daba521 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 19 Jul 2022 16:34:57 -0700 Subject: [PATCH] fix(authentication-client): Properly handle missing token error (#2700) --- packages/authentication-client/src/core.ts | 2 +- packages/authentication-client/test/index.test.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/authentication-client/src/core.ts b/packages/authentication-client/src/core.ts index e1b2c33512..07db6190f4 100644 --- a/packages/authentication-client/src/core.ts +++ b/packages/authentication-client/src/core.ts @@ -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({ diff --git a/packages/authentication-client/test/index.test.ts b/packages/authentication-client/test/index.test.ts index 0e6708ede2..de8f9210e6 100644 --- a/packages/authentication-client/test/index.test.ts +++ b/packages/authentication-client/test/index.test.ts @@ -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 () => {