From 367b5c8d85114666716c8ddfefb6ddf1a9b3ae1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Tue, 4 May 2021 21:24:25 +0200 Subject: [PATCH] fix: logout should only be called once --- frontend/src/component/menu/routes.js | 2 +- frontend/src/component/user/logout-component.jsx | 14 +++++++++----- frontend/src/component/user/logout-container.jsx | 4 +++- frontend/src/store/feature-toggle/index.js | 1 + frontend/src/store/user/index.js | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/frontend/src/component/menu/routes.js b/frontend/src/component/menu/routes.js index a30381efa9..c111c14433 100644 --- a/frontend/src/component/menu/routes.js +++ b/frontend/src/component/menu/routes.js @@ -332,7 +332,7 @@ export const routes = [ title: 'Sign out', icon: 'exit_to_app', component: LogoutFeatures, - type: 'protected', + type: 'unprotected', layout: 'main', }, { diff --git a/frontend/src/component/user/logout-component.jsx b/frontend/src/component/user/logout-component.jsx index 2020043f68..bb4855b991 100644 --- a/frontend/src/component/user/logout-component.jsx +++ b/frontend/src/component/user/logout-component.jsx @@ -3,23 +3,27 @@ import PropTypes from 'prop-types'; import { Card, CardContent, CardHeader } from '@material-ui/core'; import { styles as commonStyles } from '../common'; -const LogoutComponent = ({ logoutUser, history }) => { +const LogoutComponent = ({ logoutUser, user }) => { useEffect(() => { - logoutUser(); - }); + if(user) { + logoutUser(); + } + }, [user, logoutUser]); return ( Logged out - You have now been successfully logged out of Unleash. Thank you - for using Unleash.{' '} + You have now been successfully logged out of Unleash. +

+ Thank you for using Unleash.{' '}
); }; LogoutComponent.propTypes = { logoutUser: PropTypes.func.isRequired, + user: PropTypes.object, }; export default LogoutComponent; diff --git a/frontend/src/component/user/logout-container.jsx b/frontend/src/component/user/logout-container.jsx index 115949d841..1e5f79c125 100644 --- a/frontend/src/component/user/logout-container.jsx +++ b/frontend/src/component/user/logout-container.jsx @@ -6,6 +6,8 @@ const mapDispatchToProps = { logoutUser, }; -const mapStateToProps = () => ({}); +const mapStateToProps = (state) => ({ + user: state.user.get('profile'), +}); export default connect(mapStateToProps, mapDispatchToProps)(LogoutComponent); diff --git a/frontend/src/store/feature-toggle/index.js b/frontend/src/store/feature-toggle/index.js index 3881c8a068..30fee69809 100644 --- a/frontend/src/store/feature-toggle/index.js +++ b/frontend/src/store/feature-toggle/index.js @@ -62,6 +62,7 @@ const features = (state = new List([]), action) => { return new List(action.featureToggles.map($Map)); case USER_LOGIN: case USER_LOGOUT: + console.log('clear toggle store'); debug(USER_LOGOUT, action); return new List([]); default: diff --git a/frontend/src/store/user/index.js b/frontend/src/store/user/index.js index 6ccbcc9a6d..8e9214bc3a 100644 --- a/frontend/src/store/user/index.js +++ b/frontend/src/store/user/index.js @@ -17,7 +17,7 @@ const userStore = (state = new $Map({permissions: []}), action) => { .set('showDialog', true); return state; case USER_LOGOUT: - return new $Map(); + return new $Map({permissions: []}); default: return state; }