Skip to content

Commit

Permalink
initializes the auth state on logout to fix loading issue, fixes envi…
Browse files Browse the repository at this point in the history
…roment detection
  • Loading branch information
dauglyon committed Oct 18, 2023
1 parent 05a2c42 commit cf828a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
Expand Down
3 changes: 2 additions & 1 deletion src/features/layout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
7 changes: 5 additions & 2 deletions src/features/legacy/Legacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');
}
});

Expand Down

0 comments on commit cf828a6

Please sign in to comment.