Skip to content

Commit

Permalink
feat: add force-logout stream listener (#5643)
Browse files Browse the repository at this point in the history
* feat: add force-logout stream listener

* Update app/lib/services/connect.ts
  • Loading branch information
dnlsilva authored Apr 25, 2024
1 parent 3918b56 commit a1fb966
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/lib/services/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import protectedFunction from '../methods/helpers/protectedFunction';
import database from '../database';
import { twoFactor } from './twoFactor';
import { store } from '../store/auxStore';
import { loginRequest, setLoginServices, setUser } from '../../actions/login';
import { loginRequest, logout, setLoginServices, setUser } from '../../actions/login';
import sdk from './sdk';
import I18n from '../../i18n';
import { ICredentials, ILoggedUser, STATUSES } from '../../definitions';
Expand Down Expand Up @@ -46,6 +46,7 @@ let usersListener: any;
let notifyAllListener: any;
let rolesListener: any;
let notifyLoggedListener: any;
let logoutListener: any;

function connect({ server, logoutOnError = false }: { server: string; logoutOnError?: boolean }): Promise<void> {
return new Promise<void>(resolve => {
Expand Down Expand Up @@ -89,6 +90,10 @@ function connect({ server, logoutOnError = false }: { server: string; logoutOnEr
notifyLoggedListener.then(stopListener);
}

if (logoutListener) {
logoutListener.then(stopListener);
}

unsubscribeRooms();

EventEmitter.emit('INQUIRY_UNSUBSCRIBE');
Expand Down Expand Up @@ -270,6 +275,8 @@ function connect({ server, logoutOnError = false }: { server: string; logoutOnEr
})
);

logoutListener = sdk.current.onStreamData('stream-force_logout', () => store.dispatch(logout(true)));

resolve();
});
}
Expand Down

0 comments on commit a1fb966

Please sign in to comment.