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: sign out other instance when logged in with new instance [WPB-15071] #18710

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/script/auth/page/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -49,6 +50,7 @@ type Props = React.HTMLProps<HTMLDivElement>;

const IndexComponent = ({defaultSSOCode, doInit}: Props & ConnectedProps & DispatchProps) => {
const navigate = useNavigate();
const {hasOtherInstance} = useSingleInstance();
const core = container.resolve(Core);
const [logoutReason, setLogoutReason] = useState<string>();

Expand All @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions src/script/components/AppContainer/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -53,6 +55,7 @@ interface AppProps {
export const AppContainer: FC<AppProps> = ({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;
Expand Down Expand Up @@ -87,7 +90,13 @@ export const AppContainer: FC<AppProps> = ({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;
}

Expand Down
Loading