From 7bd5172d731071163a0d7faa30cd4f98e5e93d79 Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Tue, 18 Feb 2025 14:33:39 +0800 Subject: [PATCH] fix: removed extra check --- src/components/layout/index.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/layout/index.tsx b/src/components/layout/index.tsx index 8a9029c9..c9c62aa7 100644 --- a/src/components/layout/index.tsx +++ b/src/components/layout/index.tsx @@ -10,6 +10,12 @@ import AppHeader from './header'; import Body from './main-body'; import './layout.scss'; +function hasAllKeys(obj1, obj2) { + const keys1 = Object.keys(obj1); + const keys2 = new Set(Object.keys(obj2)); + return keys1.every(key => keys2.has(key)); +} + const Layout = () => { const { isDesktop } = useDevice(); @@ -18,20 +24,21 @@ const Layout = () => { const isCallbackPage = window.location.pathname === '/callback'; const isLoggedInCookie = Cookies.get('logged_state') === 'true'; const isEndpointPage = window.location.pathname.includes('endpoint'); - const clientAccounts = JSON.parse(localStorage.getItem('accountsList') ?? '{}'); const checkClientAccount = JSON.parse(localStorage.getItem('clientAccounts') ?? '{}'); const checkAccountList = JSON.parse(localStorage.getItem('accountList') ?? '{}'); - const accountLengthsEqual = Object.keys(clientAccounts).length === Object.keys(checkClientAccount).length; + const cookiesAccount = JSON.parse(Cookies.get('client.accounts') ?? '{}'); + const isAccountPresent = hasAllKeys(checkClientAccount, cookiesAccount); + + console.log('clientAccounts', { checkClientAccount, checkAccountList, isAccountPresent }); - console.log('clientAccounts', { checkClientAccount, checkAccountList, accountLengthsEqual }); useEffect(() => { - if (isLoggedInCookie && isOAuth2Enabled && !isEndpointPage && !isCallbackPage && !accountLengthsEqual) { + if (isLoggedInCookie && isOAuth2Enabled && !isEndpointPage && !isCallbackPage && !isAccountPresent) { console.log('requestOidcAuthentication'); requestOidcAuthentication({ redirectCallbackUri: `${window.location.origin}/callback`, }); } - }, [isLoggedInCookie, isOAuth2Enabled, isEndpointPage, isCallbackPage, accountLengthsEqual]); + }, [isLoggedInCookie, isOAuth2Enabled, isEndpointPage, isCallbackPage, isAccountPresent]); return (