From 9a3d0f9a0ea20a15cbd26bc281cb92698df1352a Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Thu, 20 Feb 2025 07:37:23 +0800 Subject: [PATCH] fix: oauth route after the callback --- src/components/layout/index.tsx | 36 ++++++++++++++-------------- src/pages/callback/callback-page.tsx | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/layout/index.tsx b/src/components/layout/index.tsx index 15fccf7f..b9ea0e60 100644 --- a/src/components/layout/index.tsx +++ b/src/components/layout/index.tsx @@ -29,7 +29,7 @@ const Layout = () => { Object.values(checkClientAccount).some(account => account.currency === currency) || currency === 'demo' || currency === ''; - const [clientHasCurrency] = useState(ifClientAccountHasCurrency); + const [clientHasCurrency, setClientHasCurrency] = useState(ifClientAccountHasCurrency); const validCurrencies = [...fiat_currencies_display_order, ...crypto_currencies_display_order]; const query_currency = (getQueryParams.get('account') ?? '')?.toUpperCase(); @@ -40,21 +40,21 @@ const Layout = () => { const validateApiAccounts = ({ data }: any) => { if (data.msg_type === 'authorize') { api_accounts.push(data.authorize.account_list || []); - console.log('api_accounts', api_accounts); - console.log('checkClientAccount', checkClientAccount); - api_accounts?.flat().map(data => { - Object.values(checkClientAccount).map(key => { - console.log('outside data.currency', data.currency); - console.log('outside key.currency', key.currency); - if (data.currency !== key.currency) { - console.log('setClientHasCurrency'); - console.log('data.currency', data.currency); - console.log('key.currency', key.currency); - //setClientHasCurrency(false); - } - }); + const allCurrencies = new Set(Object.values(checkClientAccount).map(acc => acc.currency)); + + const hasMissingCurrency = api_accounts?.flat().some(data => { + if (!allCurrencies.has(data.currency)) { + return true; + } + return false; }); + if (hasMissingCurrency) { + setClientHasCurrency(false); + } else { + console.log('All currencies are present'); + } + if (subscription) { subscription?.unsubscribe(); } @@ -68,11 +68,11 @@ const Layout = () => { } }, []); - console.log('clientHasCurrency', clientHasCurrency); - useEffect(() => { - if (isLoggedInCookie && !isClientAccountsPopulated && isOAuth2Enabled && !isEndpointPage && !isCallbackPage) { - console.log('requestOidcAuthentication'); + if ( + (isLoggedInCookie && !isClientAccountsPopulated && isOAuth2Enabled && !isEndpointPage && !isCallbackPage) || + !clientHasCurrency + ) { requestOidcAuthentication({ redirectCallbackUri: `${window.location.origin}/callback`, }); diff --git a/src/pages/callback/callback-page.tsx b/src/pages/callback/callback-page.tsx index 9218a890..5283a80e 100644 --- a/src/pages/callback/callback-page.tsx +++ b/src/pages/callback/callback-page.tsx @@ -53,7 +53,7 @@ const CallbackPage = () => { localStorage.setItem('active_loginid', tokens.acct1); } - window.location.assign('/'); + window.location.assign(window.history.state?.from || '/'); }} renderReturnButton={() => { return (