Skip to content

Commit

Permalink
feat: implement user redirection to oauth page
Browse files Browse the repository at this point in the history
  • Loading branch information
shayan-deriv committed Jun 10, 2024
1 parent eacfffc commit bb72de2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
27 changes: 11 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@babel/preset-env": "^7.24.5",
"@deriv-com/api-hooks": "^0.1.24",
"@deriv-com/api-hooks": "^1.0.10",
"@deriv-com/translations": "^1.2.4",
"@deriv-com/ui": "^1.27.9",
"@deriv-com/utils": "latest",
Expand Down
27 changes: 10 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { BrowserRouter } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
import { AppFooter, AppHeader, DerivIframe } from '@/components';
import { useAccountList, useAuthData } from '@deriv-com/api-hooks';
import { getOauthUrl } from '@/constants';
import AppContent from '@/routes/AppContent';
import { getCurrentRoute } from '@/utils';
import { useAuthData } from '@deriv-com/api-hooks';
import { initializeI18n, TranslationProvider } from '@deriv-com/translations';
import { useDevice } from '@deriv-com/ui';
import AppContent from './routes/AppContent';
import { getOauthUrl } from './constants';

const { VITE_CROWDIN_BRANCH_NAME, VITE_PROJECT_NAME, VITE_TRANSLATIONS_CDN_URL } = import.meta.env;
const i18nInstance = initializeI18n({
Expand All @@ -17,23 +18,15 @@ const i18nInstance = initializeI18n({

const App = () => {
const { isDesktop } = useDevice();
const { data: accountList } = useAccountList();
const { activeLoginid, isAuthorized } = useAuthData();
const { isAuthorized, isAuthorizing } = useAuthData();
const isEndpointPage = getCurrentRoute() === 'endpoint';

const oauthUrl = getOauthUrl();
useEffect(() => {
const hasActiveLoginid = !!activeLoginid;
const hasAccounts = !!accountList?.length;
const shouldRedirectToLogin = !isAuthorized && !hasActiveLoginid && !hasAccounts;
console.log('isAuthorized', isAuthorized);
console.log('hasActiveLoginid', hasActiveLoginid);
console.log('hasAccounts', hasAccounts);
console.log('shouldRedirectToLogin', shouldRedirectToLogin);
console.log('====');
// if (shouldRedirectToLogin) {
// window.open(oauthUrl, '_self');
// }
}, [accountList, activeLoginid, isAuthorized, oauthUrl]);
if (!isEndpointPage && !isAuthorized && !isAuthorizing) {
window.open(oauthUrl, '_self');
}
}, [isAuthorized, isAuthorizing, isEndpointPage, oauthUrl]);

return (
<BrowserRouter>
Expand Down

0 comments on commit bb72de2

Please sign in to comment.