Skip to content

Commit 8211b98

Browse files
authored
fix: Do not error in authentication client on logout (#1473)
1 parent e935df9 commit 8211b98

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

packages/authentication-client/src/core.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,20 @@ export class AuthenticationClient {
166166

167167
logout () {
168168
return Promise.resolve(this.app.get('authentication'))
169-
.then(() => this.service.remove(null))
170-
.then((authResult: AuthenticationResult) => this.removeAccessToken()
171-
.then(() => this.reset())
172-
.then(() => {
173-
this.app.emit('logout', authResult);
174-
175-
return authResult;
176-
})
177-
);
169+
.then(auth => {
170+
if (!auth) {
171+
return null;
172+
}
173+
174+
return this.service.remove(null)
175+
.then((authResult: AuthenticationResult) => this.removeAccessToken()
176+
.then(() => this.reset())
177+
.then(() => {
178+
this.app.emit('logout', authResult);
179+
180+
return authResult;
181+
})
182+
);
183+
});
178184
}
179185
}

packages/authentication-client/test/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ describe('@feathersjs/authentication-client', () => {
2424
},
2525

2626
remove (id) {
27+
if (!app.get('authentication')) {
28+
throw new Error('Not logged in');
29+
}
30+
2731
return Promise.resolve({ id });
2832
}
2933
});
@@ -131,6 +135,12 @@ describe('@feathersjs/authentication-client', () => {
131135
});
132136
});
133137

138+
it('logout when not logged in without error', async () => {
139+
const result = await app.logout();
140+
141+
assert.strictEqual(result, null);
142+
});
143+
134144
describe('reauthenticate', () => {
135145
it('fails when no token in storage', () => {
136146
return app.authentication.reAuthenticate().then(() => {

0 commit comments

Comments
 (0)