Skip to content

Commit 4871d72

Browse files
chore: wait for traders hub redirection to check before sso kicks in
1 parent e82d39b commit 4871d72

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

packages/core/src/App/AppContent.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough }
5050
setIsPhoneNumberVerificationEnabled,
5151
setIsCountryCodeDropdownEnabled,
5252
accounts,
53+
prevent_single_login,
5354
} = store.client;
5455
const { first_name, last_name } = account_settings;
5556
const { current_language, changeSelectedLanguage } = store.common;
@@ -72,6 +73,7 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough }
7273
is_client_store_initialized,
7374
isOAuth2Enabled,
7475
oAuthLogout,
76+
prevent_single_login,
7577
});
7678

7779
const [isWebPasskeysFFEnabled, isGBLoaded] = useGrowthbookIsOn({

packages/core/src/App/Containers/RootComponent/root-component.jsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const RootComponent = observer(props => {
2525
setIsWalletsOnboardingTourGuideVisible,
2626
notification_messages_ui,
2727
} = ui;
28-
const { has_wallet, logout, prevent_redirect_to_hub, is_client_store_initialized } = client;
28+
const { has_wallet, logout, prevent_redirect_to_hub, is_client_store_initialized, setPreventSingleLogin } = client;
2929

3030
const { oAuthLogout } = useOauth2({ handleLogout: logout });
3131

@@ -37,6 +37,10 @@ const RootComponent = observer(props => {
3737
const PRODUCTION_REDIRECT_URL = 'https://hub.deriv.com/tradershub/home';
3838
const STAGING_REDIRECT_URL = 'https://staging-hub.deriv.com/tradershub/home';
3939

40+
useEffect(() => {
41+
setPreventSingleLogin(true);
42+
}, []);
43+
4044
useEffect(() => {
4145
if (isHubRedirectionEnabled && has_wallet && !prevent_redirect_to_hub && is_client_store_initialized) {
4246
const redirectUrl = process.env.NODE_ENV === 'production' ? PRODUCTION_REDIRECT_URL : STAGING_REDIRECT_URL;
@@ -50,6 +54,11 @@ const RootComponent = observer(props => {
5054
localStorage.removeItem('active_wallet_loginid');
5155
window.location.assign(redirectUrl);
5256
}
57+
58+
const shouldStayInDerivApp = !isHubRedirectionEnabled || !has_wallet || prevent_redirect_to_hub;
59+
if (is_client_store_initialized && shouldStayInDerivApp) {
60+
setPreventSingleLogin(false);
61+
}
5362
}, [isHubRedirectionEnabled, has_wallet, prevent_redirect_to_hub, is_client_store_initialized]);
5463

5564
return has_wallet ? (

packages/core/src/Stores/client-store.js

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default class ClientStore extends BaseStore {
115115
currency: '',
116116
};
117117
prevent_redirect_to_hub = false;
118+
prevent_single_login = false;
118119

119120
verification_code = {
120121
signup: '',
@@ -241,6 +242,7 @@ export default class ClientStore extends BaseStore {
241242
prev_real_account_loginid: observable,
242243
prev_account_type: observable,
243244
prevent_redirect_to_hub: observable,
245+
prevent_single_login: observable,
244246
phone_settings: observable,
245247
is_already_attempted: observable,
246248
is_p2p_enabled: observable,
@@ -951,6 +953,10 @@ export default class ClientStore extends BaseStore {
951953
this.prevent_redirect_to_hub = value;
952954
};
953955

956+
setPreventSingleLogin = value => {
957+
this.prevent_single_login = value;
958+
};
959+
954960
getIsMarketTypeMatching = (account, market_type) => {
955961
if (market_type === 'synthetic') {
956962
return account.market_type === market_type || account.market_type === 'gaming';

packages/hooks/src/useSilentLoginAndLogout.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ const useSilentLoginAndLogout = ({
1616
is_client_store_initialized,
1717
isOAuth2Enabled,
1818
oAuthLogout,
19+
prevent_single_login,
1920
}: {
2021
is_client_store_initialized: boolean;
2122
isOAuth2Enabled: boolean;
2223
oAuthLogout: () => Promise<void>;
24+
prevent_single_login: boolean;
2325
}) => {
2426
const loggedState = Cookies.get('logged_state');
2527

@@ -29,6 +31,7 @@ const useSilentLoginAndLogout = ({
2931
window.location.pathname.includes('callback') || window.location.pathname.includes('endpoint');
3032

3133
useEffect(() => {
34+
if (prevent_single_login) return;
3235
// NOTE: Remove this logic once social signup is intergated with OIDC
3336
const params = new URLSearchParams(window.location.search);
3437
const isUsingLegacyFlow = params.has('token1') && params.has('acct1');
@@ -68,6 +71,7 @@ const useSilentLoginAndLogout = ({
6871
isOAuth2Enabled,
6972
oAuthLogout,
7073
isSilentLoginExcluded,
74+
prevent_single_login,
7175
]);
7276
};
7377

packages/stores/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ export type TClientStore = {
542542
standpoint: TStandPoint;
543543
is_p2p_available: boolean;
544544
prevent_redirect_to_hub: boolean;
545+
prevent_single_login: boolean;
545546
setPreventRedirectToHub: (value: boolean) => void;
547+
setPreventSingleLogin: (value: boolean) => void;
546548
setAccountStatus: (status?: GetAccountStatus) => void;
547549
setBalanceOtherAccounts: (balance: number) => void;
548550
selectCurrency: (currency: string) => void;

0 commit comments

Comments
 (0)