Skip to content

Commit

Permalink
Adrienne / Fix SSO triggering twice before redirecting to Traders Hub (
Browse files Browse the repository at this point in the history
…#18109)

* feat: store redirect metadata for traders hub from os-redirect

* Merge branch 'master' of github.com:deriv-com/deriv-app

* chore: wait for traders hub redirection to check before sso kicks in

* chore: wait for feature flag redirection to be loaded

* chore: fixed typing
  • Loading branch information
adrienne-deriv authored Mar 6, 2025
1 parent 9eddb5f commit c72eaf6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/App/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough }
setIsPhoneNumberVerificationEnabled,
setIsCountryCodeDropdownEnabled,
accounts,
prevent_single_login,
} = store.client;
const { first_name, last_name } = account_settings;
const { current_language, changeSelectedLanguage } = store.common;
Expand All @@ -72,6 +73,7 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough }
is_client_store_initialized,
isOAuth2Enabled,
oAuthLogout,
prevent_single_login,
});

const [isWebPasskeysFFEnabled, isGBLoaded] = useGrowthbookIsOn({
Expand Down
21 changes: 18 additions & 3 deletions packages/core/src/App/Containers/RootComponent/root-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ const RootComponent = observer(props => {
setIsWalletsOnboardingTourGuideVisible,
notification_messages_ui,
} = ui;
const { has_wallet, logout, prevent_redirect_to_hub, is_client_store_initialized } = client;
const { has_wallet, logout, prevent_redirect_to_hub, is_client_store_initialized, setPreventSingleLogin } = client;

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

const onWalletsOnboardingTourGuideCloseHandler = () => {
setIsWalletsOnboardingTourGuideVisible(false);
};
const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled();
const { isHubRedirectionEnabled, isHubRedirectionLoaded } = useIsHubRedirectionEnabled();

const PRODUCTION_REDIRECT_URL = 'https://hub.deriv.com/tradershub/home';
const STAGING_REDIRECT_URL = 'https://staging-hub.deriv.com/tradershub/home';

useEffect(() => {
setPreventSingleLogin(true);
}, []);

useEffect(() => {
if (isHubRedirectionEnabled && has_wallet && !prevent_redirect_to_hub && is_client_store_initialized) {
const redirectUrl = process.env.NODE_ENV === 'production' ? PRODUCTION_REDIRECT_URL : STAGING_REDIRECT_URL;
Expand All @@ -50,7 +54,18 @@ const RootComponent = observer(props => {
localStorage.removeItem('active_wallet_loginid');
window.location.assign(redirectUrl);
}
}, [isHubRedirectionEnabled, has_wallet, prevent_redirect_to_hub, is_client_store_initialized]);

const shouldStayInDerivApp = !isHubRedirectionEnabled || !has_wallet || prevent_redirect_to_hub;
if (isHubRedirectionLoaded && is_client_store_initialized && shouldStayInDerivApp) {
setPreventSingleLogin(false);
}
}, [
isHubRedirectionLoaded,
isHubRedirectionEnabled,
has_wallet,
prevent_redirect_to_hub,
is_client_store_initialized,
]);

return has_wallet ? (
<Wallets
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class ClientStore extends BaseStore {
currency: '',
};
prevent_redirect_to_hub = false;
prevent_single_login = false;

verification_code = {
signup: '',
Expand Down Expand Up @@ -241,6 +242,7 @@ export default class ClientStore extends BaseStore {
prev_real_account_loginid: observable,
prev_account_type: observable,
prevent_redirect_to_hub: observable,
prevent_single_login: observable,
phone_settings: observable,
is_already_attempted: observable,
is_p2p_enabled: observable,
Expand Down Expand Up @@ -951,6 +953,10 @@ export default class ClientStore extends BaseStore {
this.prevent_redirect_to_hub = value;
};

setPreventSingleLogin = value => {
this.prevent_single_login = value;
};

getIsMarketTypeMatching = (account, market_type) => {
if (market_type === 'synthetic') {
return account.market_type === market_type || account.market_type === 'gaming';
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useIsHubRedirectionEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type THubEnabledCountryList = {
};

const useIsHubRedirectionEnabled = () => {
const [hubEnabledCountryList] = useGrowthbookGetFeatureValue({
const [hubEnabledCountryList, isHubRedirectionLoaded] = useGrowthbookGetFeatureValue({
featureFlag: 'hub_enabled_country_list',
});
const { client } = useStore();
Expand All @@ -29,7 +29,7 @@ const useIsHubRedirectionEnabled = () => {
clients_country &&
(hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(clients_country);

return { isHubRedirectionEnabled, isChangingToHubAppId };
return { isHubRedirectionEnabled, isChangingToHubAppId, isHubRedirectionLoaded };
};

export default useIsHubRedirectionEnabled;
4 changes: 4 additions & 0 deletions packages/hooks/src/useSilentLoginAndLogout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const useSilentLoginAndLogout = ({
is_client_store_initialized,
isOAuth2Enabled,
oAuthLogout,
prevent_single_login,
}: {
is_client_store_initialized: boolean;
isOAuth2Enabled: boolean;
oAuthLogout: () => Promise<void>;
prevent_single_login?: boolean;
}) => {
const loggedState = Cookies.get('logged_state');

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

useEffect(() => {
if (prevent_single_login) return;
// NOTE: Remove this logic once social signup is intergated with OIDC
const params = new URLSearchParams(window.location.search);
const isUsingLegacyFlow = params.has('token1') && params.has('acct1');
Expand Down Expand Up @@ -68,6 +71,7 @@ const useSilentLoginAndLogout = ({
isOAuth2Enabled,
oAuthLogout,
isSilentLoginExcluded,
prevent_single_login,
]);
};

Expand Down
2 changes: 2 additions & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ export type TClientStore = {
standpoint: TStandPoint;
is_p2p_available: boolean;
prevent_redirect_to_hub: boolean;
prevent_single_login: boolean;
setPreventRedirectToHub: (value: boolean) => void;
setPreventSingleLogin: (value: boolean) => void;
setAccountStatus: (status?: GetAccountStatus) => void;
setBalanceOtherAccounts: (balance: number) => void;
selectCurrency: (currency: string) => void;
Expand Down

0 comments on commit c72eaf6

Please sign in to comment.