From fa9a1c314516bc9d3752ac718b4174222a5f76f7 Mon Sep 17 00:00:00 2001 From: Fredrik Oseberg Date: Mon, 12 Apr 2021 16:25:38 +0200 Subject: [PATCH] fix: logout redirect logic --- frontend/src/component/App.tsx | 6 +++--- frontend/src/component/user/Login/Login.jsx | 1 + frontend/src/store/user/actions.js | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/component/App.tsx b/frontend/src/component/App.tsx index 6b79a53191..5431bd8d60 100644 --- a/frontend/src/component/App.tsx +++ b/frontend/src/component/App.tsx @@ -27,9 +27,9 @@ const App = ({ location, user }: IAppProps) => { const isUnauthorized = () => { // authDetails only exists if the user is not logged in. - return ( - user?.authDetails !== undefined || Object.keys(user).length === 0 - ); + + if (Object.keys(user).length === 0) return false; + return user?.authDetails !== undefined; }; // Change this to IRoute once snags with HashRouter and TS is worked out diff --git a/frontend/src/component/user/Login/Login.jsx b/frontend/src/component/user/Login/Login.jsx index c473e8c551..1e5f8424b0 100644 --- a/frontend/src/component/user/Login/Login.jsx +++ b/frontend/src/component/user/Login/Login.jsx @@ -17,6 +17,7 @@ const Login = ({ history, loadInitialData, isUnauthorized, authDetails }) => { const smallScreen = useMediaQuery(theme.breakpoints.up('md')); useEffect(() => { + console.log(isUnauthorized()); if (isUnauthorized()) { loadInitialData(); } else { diff --git a/frontend/src/store/user/actions.js b/frontend/src/store/user/actions.js index 4487e7cb8e..6798f39ebb 100644 --- a/frontend/src/store/user/actions.js +++ b/frontend/src/store/user/actions.js @@ -57,6 +57,7 @@ export function logoutUser() { .logoutUser() .then(() => dispatch({ type: USER_LOGOUT })) .then(() => dispatch({ type: RESET_LOADING })) + .then(() => (window.location = '/')) .catch(handleError); }; }