Skip to content

Commit

Permalink
fix(authentication-client): Reset authentication promise on socket di…
Browse files Browse the repository at this point in the history
…sconnect (#1696)
  • Loading branch information
daffl committed Nov 21, 2019
1 parent f5d0ddd commit 3951626
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/authentication-client/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ export class AuthenticationClient {
handleSocket (socket: any) {
// Connection events happen on every reconnect
const connected = this.app.io ? 'connect' : 'open';
const disconnected = this.app.io ? 'disconnect' : 'disconnection';

socket.on(connected, () => {
socket.on(disconnected, () => {
const authPromise = new Promise(resolve =>
socket.once(connected, () => resolve())
)
// Only reconnect when `reAuthenticate()` or `authenticate()`
// has been called explicitly first
if (this.authenticated) {
// Force reauthentication with the server
this.reAuthenticate(true);
}
// Force reauthentication with the server
.then(() => this.authenticated ? this.reAuthenticate(true) : null);

this.app.set('authentication', authPromise);
});
}

Expand Down

0 comments on commit 3951626

Please sign in to comment.