feat: add force-logout stream listener (#5643)

* feat: add force-logout stream listener

* Update app/lib/services/connect.ts
This commit is contained in:
Gleidson Daniel Silva 2024-04-25 17:31:23 -03:00 committed by GitHub
parent 3918b56a82
commit a1fb966446
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -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';
@ -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 => {
@ -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');
@ -270,6 +275,8 @@ function connect({ server, logoutOnError = false }: { server: string; logoutOnEr
})
);
logoutListener = sdk.current.onStreamData('stream-force_logout', () => store.dispatch(logout(true)));
resolve();
});
}