Skip to content

Commit 7bd5172

Browse files
committed
fix: removed extra check
1 parent 87dcefe commit 7bd5172

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/components/layout/index.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import AppHeader from './header';
1010
import Body from './main-body';
1111
import './layout.scss';
1212

13+
function hasAllKeys(obj1, obj2) {
14+
const keys1 = Object.keys(obj1);
15+
const keys2 = new Set(Object.keys(obj2));
16+
return keys1.every(key => keys2.has(key));
17+
}
18+
1319
const Layout = () => {
1420
const { isDesktop } = useDevice();
1521

@@ -18,20 +24,21 @@ const Layout = () => {
1824
const isCallbackPage = window.location.pathname === '/callback';
1925
const isLoggedInCookie = Cookies.get('logged_state') === 'true';
2026
const isEndpointPage = window.location.pathname.includes('endpoint');
21-
const clientAccounts = JSON.parse(localStorage.getItem('accountsList') ?? '{}');
2227
const checkClientAccount = JSON.parse(localStorage.getItem('clientAccounts') ?? '{}');
2328
const checkAccountList = JSON.parse(localStorage.getItem('accountList') ?? '{}');
24-
const accountLengthsEqual = Object.keys(clientAccounts).length === Object.keys(checkClientAccount).length;
29+
const cookiesAccount = JSON.parse(Cookies.get('client.accounts') ?? '{}');
30+
const isAccountPresent = hasAllKeys(checkClientAccount, cookiesAccount);
31+
32+
console.log('clientAccounts', { checkClientAccount, checkAccountList, isAccountPresent });
2533

26-
console.log('clientAccounts', { checkClientAccount, checkAccountList, accountLengthsEqual });
2734
useEffect(() => {
28-
if (isLoggedInCookie && isOAuth2Enabled && !isEndpointPage && !isCallbackPage && !accountLengthsEqual) {
35+
if (isLoggedInCookie && isOAuth2Enabled && !isEndpointPage && !isCallbackPage && !isAccountPresent) {
2936
console.log('requestOidcAuthentication');
3037
requestOidcAuthentication({
3138
redirectCallbackUri: `${window.location.origin}/callback`,
3239
});
3340
}
34-
}, [isLoggedInCookie, isOAuth2Enabled, isEndpointPage, isCallbackPage, accountLengthsEqual]);
41+
}, [isLoggedInCookie, isOAuth2Enabled, isEndpointPage, isCallbackPage, isAccountPresent]);
3542

3643
return (
3744
<div className={clsx('layout', { responsive: isDesktop })}>

0 commit comments

Comments
 (0)