Skip to content

Commit

Permalink
fix: fix issue with expired auth0 token causing incorrect impersonati…
Browse files Browse the repository at this point in the history
…on mode state
  • Loading branch information
sunilsabatp committed Aug 29, 2024
1 parent 625d3e1 commit 386f6bb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/features/common/Layout/UserPropsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>(null);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 386f6bb

Please sign in to comment.