diff --git a/src/script/auth/page/Index.tsx b/src/script/auth/page/Index.tsx index a459112a10b..5bbda263851 100644 --- a/src/script/auth/page/Index.tsx +++ b/src/script/auth/page/Index.tsx @@ -29,6 +29,7 @@ import {UrlUtil} from '@wireapp/commons'; import {Button, ButtonVariant, ContainerXS, ErrorMessage, Text} from '@wireapp/react-ui-kit'; import {LogoFullIcon} from 'Components/Icon'; +import {useSingleInstance} from 'Hooks/useSingleInstance'; import {Core} from 'src/script/service/CoreSingleton'; import {isDataDogEnabled} from 'Util/DataDog'; import {getWebEnvironment} from 'Util/Environment'; @@ -49,6 +50,7 @@ type Props = React.HTMLProps; const IndexComponent = ({defaultSSOCode, doInit}: Props & ConnectedProps & DispatchProps) => { const navigate = useNavigate(); + const {hasOtherInstance} = useSingleInstance(); const core = container.resolve(Core); const [logoutReason, setLogoutReason] = useState(); @@ -62,10 +64,10 @@ const IndexComponent = ({defaultSSOCode, doInit}: Props & ConnectedProps & Dispa const immediateLogin = useCallback(async () => { await doInit({isImmediateLogin: true, shouldValidateLocalClient: true}); // Check if the user is already logged in - if (core.getLocalClient()) { + if (!hasOtherInstance && core.getLocalClient()) { navigate(ROUTE.HISTORY_INFO); } - }, [core, doInit, navigate]); + }, [core, doInit, navigate, hasOtherInstance]); useEffect(() => { if (Config.getConfig().FEATURE.ENABLE_AUTO_LOGIN) { diff --git a/src/script/components/AppContainer/AppContainer.tsx b/src/script/components/AppContainer/AppContainer.tsx index 80f154aaf17..3c17e2125eb 100644 --- a/src/script/components/AppContainer/AppContainer.tsx +++ b/src/script/components/AppContainer/AppContainer.tsx @@ -20,9 +20,11 @@ import {FC, useEffect, useMemo} from 'react'; import {ClientType} from '@wireapp/api-client/lib/client/'; +import {amplify} from 'amplify'; import {container} from 'tsyringe'; import {StyledApp, THEME_ID} from '@wireapp/react-ui-kit'; +import {WebAppEvents} from '@wireapp/webapp-events'; import {DetachedCallingCell} from 'Components/calling/DetachedCallingCell'; import {PrimaryModalComponent} from 'Components/Modals/PrimaryModal/PrimaryModal'; @@ -36,7 +38,7 @@ import {isDetachedCallingFeatureEnabled} from 'Util/isDetachedCallingFeatureEnab import {useAccentColor} from './hooks/useAccentColor'; import {useTheme} from './hooks/useTheme'; -import {Configuration} from '../../Config'; +import {Config, Configuration} from '../../Config'; import {setAppLocale} from '../../localization/Localizer'; import {App} from '../../main/app'; import {AppMain} from '../../page/AppMain'; @@ -53,6 +55,7 @@ interface AppProps { export const AppContainer: FC = ({config, clientType}) => { setAppLocale(); const app = useMemo(() => new App(container.resolve(Core), container.resolve(APIClient), config), []); + const enableAutoLogin = Config.getConfig().FEATURE.ENABLE_AUTO_LOGIN; // Publishing application on the global scope for debug and testing purposes. window.wire.app = app; @@ -87,7 +90,13 @@ export const AppContainer: FC = ({config, clientType}) => { const {softLockEnabled} = useAppSoftLock(repositories.calling, repositories.notification); if (hasOtherInstance) { - app.redirectToLogin(SIGN_OUT_REASON.MULTIPLE_TABS); + // Automatically sign out the user if the user has multiple tabs open + if (enableAutoLogin) { + amplify.publish(WebAppEvents.LIFECYCLE.SIGN_OUT, SIGN_OUT_REASON.MULTIPLE_TABS); + } else { + app.redirectToLogin(SIGN_OUT_REASON.MULTIPLE_TABS); + } + return null; }