Skip to content

Commit f7c4bc4

Browse files
authored
Merge pull request #287 from rupato-deriv/Rupato/Fix--oauth-route-after-callback
fix: oauth route after the callback
2 parents 1df6d60 + 9a3d0f9 commit f7c4bc4

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/components/layout/index.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Layout = () => {
2929
Object.values(checkClientAccount).some(account => account.currency === currency) ||
3030
currency === 'demo' ||
3131
currency === '';
32-
const [clientHasCurrency] = useState(ifClientAccountHasCurrency);
32+
const [clientHasCurrency, setClientHasCurrency] = useState(ifClientAccountHasCurrency);
3333

3434
const validCurrencies = [...fiat_currencies_display_order, ...crypto_currencies_display_order];
3535
const query_currency = (getQueryParams.get('account') ?? '')?.toUpperCase();
@@ -40,21 +40,21 @@ const Layout = () => {
4040
const validateApiAccounts = ({ data }: any) => {
4141
if (data.msg_type === 'authorize') {
4242
api_accounts.push(data.authorize.account_list || []);
43-
console.log('api_accounts', api_accounts);
44-
console.log('checkClientAccount', checkClientAccount);
45-
api_accounts?.flat().map(data => {
46-
Object.values(checkClientAccount).map(key => {
47-
console.log('outside data.currency', data.currency);
48-
console.log('outside key.currency', key.currency);
49-
if (data.currency !== key.currency) {
50-
console.log('setClientHasCurrency');
51-
console.log('data.currency', data.currency);
52-
console.log('key.currency', key.currency);
53-
//setClientHasCurrency(false);
54-
}
55-
});
43+
const allCurrencies = new Set(Object.values(checkClientAccount).map(acc => acc.currency));
44+
45+
const hasMissingCurrency = api_accounts?.flat().some(data => {
46+
if (!allCurrencies.has(data.currency)) {
47+
return true;
48+
}
49+
return false;
5650
});
5751

52+
if (hasMissingCurrency) {
53+
setClientHasCurrency(false);
54+
} else {
55+
console.log('All currencies are present');
56+
}
57+
5858
if (subscription) {
5959
subscription?.unsubscribe();
6060
}
@@ -68,11 +68,11 @@ const Layout = () => {
6868
}
6969
}, []);
7070

71-
console.log('clientHasCurrency', clientHasCurrency);
72-
7371
useEffect(() => {
74-
if (isLoggedInCookie && !isClientAccountsPopulated && isOAuth2Enabled && !isEndpointPage && !isCallbackPage) {
75-
console.log('requestOidcAuthentication');
72+
if (
73+
(isLoggedInCookie && !isClientAccountsPopulated && isOAuth2Enabled && !isEndpointPage && !isCallbackPage) ||
74+
!clientHasCurrency
75+
) {
7676
requestOidcAuthentication({
7777
redirectCallbackUri: `${window.location.origin}/callback`,
7878
});

src/pages/callback/callback-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const CallbackPage = () => {
5353
localStorage.setItem('active_loginid', tokens.acct1);
5454
}
5555

56-
window.location.assign('/');
56+
window.location.assign(window.history.state?.from || '/');
5757
}}
5858
renderReturnButton={() => {
5959
return (

0 commit comments

Comments
 (0)