Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(authentication-client): Reset authentication promise on socket disconnect #1696

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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