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

Adrienne / Fix SSO being triggered before redirecting to TH #18101

Closed
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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 });

Expand All @@ -37,6 +37,10 @@ const RootComponent = observer(props => {
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,6 +54,11 @@ const RootComponent = observer(props => {
localStorage.removeItem('active_wallet_loginid');
window.location.assign(redirectUrl);
}

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

return has_wallet ? (
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: 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
Loading