Skip to content

Commit 3951626

Browse files
authored
fix(authentication-client): Reset authentication promise on socket disconnect (#1696)
1 parent f5d0ddd commit 3951626

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • packages/authentication-client/src

packages/authentication-client/src/core.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@ export class AuthenticationClient {
6161
handleSocket (socket: any) {
6262
// Connection events happen on every reconnect
6363
const connected = this.app.io ? 'connect' : 'open';
64+
const disconnected = this.app.io ? 'disconnect' : 'disconnection';
6465

65-
socket.on(connected, () => {
66+
socket.on(disconnected, () => {
67+
const authPromise = new Promise(resolve =>
68+
socket.once(connected, () => resolve())
69+
)
6670
// Only reconnect when `reAuthenticate()` or `authenticate()`
6771
// has been called explicitly first
68-
if (this.authenticated) {
69-
// Force reauthentication with the server
70-
this.reAuthenticate(true);
71-
}
72+
// Force reauthentication with the server
73+
.then(() => this.authenticated ? this.reAuthenticate(true) : null);
74+
75+
this.app.set('authentication', authPromise);
7276
});
7377
}
7478

0 commit comments

Comments
 (0)