From cf828a64dd52a5e5f4d0d0ea15e91a494756aa15 Mon Sep 17 00:00:00 2001 From: David Lyon Date: Wed, 18 Oct 2023 13:26:21 -0700 Subject: [PATCH] initializes the auth state on logout to fix loading issue, fixes enviroment detection --- src/app/App.tsx | 4 ++-- src/features/layout/TopBar.tsx | 3 ++- src/features/legacy/Legacy.tsx | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index e85996a0..8476c4ba 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -27,14 +27,14 @@ const useInitApp = () => { // Use authenticated username to load user's profile const username = useAppSelector(authUsername); const initialized = useAppSelector(authInitialized); + const environment = useAppSelector((state) => state.layout.environment); useLoggedInProfileUser(username); - // Placeholder code for determining environment. useEffect(() => { // eslint-disable-next-line no-console console.info('Static Deploy Domain:', process.env.REACT_APP_KBASE_DOMAIN); dispatch(setEnvironment(process.env.REACT_APP_KBASE_ENV ?? 'unknown')); - }, [dispatch]); + }, [dispatch, environment]); return { isLoading: !initialized }; }; diff --git a/src/features/layout/TopBar.tsx b/src/features/layout/TopBar.tsx index 3011cc1f..251f2a0b 100644 --- a/src/features/layout/TopBar.tsx +++ b/src/features/layout/TopBar.tsx @@ -154,9 +154,10 @@ const useLogout = () => { revoke(tokenId) .unwrap() .then(() => { + dispatch(resetStateAction()); + // setAuth(null) follow the state reset to initialize the page as un-Authed dispatch(setAuth(null)); toast('You have been signed out'); - dispatch(resetStateAction()); navigate('/legacy/auth2/signedout'); }) .catch(() => { diff --git a/src/features/legacy/Legacy.tsx b/src/features/legacy/Legacy.tsx index b55b9d03..aae94569 100644 --- a/src/features/legacy/Legacy.tsx +++ b/src/features/legacy/Legacy.tsx @@ -4,6 +4,8 @@ import { usePageTitle } from '../layout/layoutSlice'; import { useTryAuthFromToken } from '../auth/hooks'; import { useAppDispatch } from '../../common/hooks'; import { resetStateAction } from '../../app/store'; +import { setAuth } from '../auth/authSlice'; +import { toast } from 'react-hot-toast'; export const LEGACY_BASE_ROUTE = '/legacy'; @@ -51,9 +53,10 @@ export default function Legacy() { setReceivedToken(d.payload.token); } } else if (isLogoutMessage(d)) { - // eslint-disable-next-line no-console - console.info('Logged Out'); dispatch(resetStateAction()); + dispatch(setAuth(null)); + toast('You have been signed out'); + navigate('/legacy/auth2/signedout'); } });