diff --git a/app/lib/services/connect.ts b/app/lib/services/connect.ts index 92dc4f0cfa..527a9653fa 100644 --- a/app/lib/services/connect.ts +++ b/app/lib/services/connect.ts @@ -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 { return new Promise(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(); }); }