From 386f6bb80c02f4823b3cd6ba866a591ffc488a24 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:35:57 +0530 Subject: [PATCH] fix: fix issue with expired auth0 token causing incorrect impersonation mode state --- src/features/common/Layout/UserPropsContext.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/features/common/Layout/UserPropsContext.tsx b/src/features/common/Layout/UserPropsContext.tsx index ed2cb8d8c..c9450e29f 100644 --- a/src/features/common/Layout/UserPropsContext.tsx +++ b/src/features/common/Layout/UserPropsContext.tsx @@ -45,6 +45,7 @@ export const UserPropsProvider: FC = ({ children }) => { user, error, } = useAuth0(); + console.log(useAuth0(), '=1'); const { tenantConfig } = useTenant(); const [contextLoaded, setContextLoaded] = React.useState(false); const [token, setToken] = React.useState(null); @@ -120,9 +121,16 @@ export const UserPropsProvider: FC = ({ children }) => { }, [token, refetchUserData]); React.useEffect(() => { + if (!isLoading && user === undefined) { + localStorage.removeItem('impersonationData'); + } const impersonationData = localStorage.getItem('impersonationData'); - setIsImpersonationModeOn(impersonationData !== null); - }, [isImpersonationModeOn]); + if (impersonationData !== null && !isImpersonationModeOn) { + setIsImpersonationModeOn(true); + } else if (impersonationData === null && isImpersonationModeOn) { + setIsImpersonationModeOn(false); + } + }, [user, isLoading]); const value: UserPropsContextInterface | null = { contextLoaded,