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 () => {