From 7668b9c6689134454eaccd1676f0785f008d76bd Mon Sep 17 00:00:00 2001 From: Patrick Schlangen Date: Mon, 2 Sep 2024 22:11:16 +0200 Subject: [PATCH] frontend: Flush complete redux state on logout Closes #246 --- frontend/src/redux/actionTypes.js | 3 ++- frontend/src/redux/actions.js | 4 +--- frontend/src/redux/reducers/index.js | 13 +++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/frontend/src/redux/actionTypes.js b/frontend/src/redux/actionTypes.js index bd353f5f..c04b76f9 100644 --- a/frontend/src/redux/actionTypes.js +++ b/frontend/src/redux/actionTypes.js @@ -5,5 +5,6 @@ export const ActionTypes = { SET_TIMEZONES: 'SET_TIMEZONES', SET_USER_PROFILE: 'SET_USER_PROFILE', SET_UI_SETTING: 'SET_UI_SETTING', - SET_FOLDERS: 'SET_FOLDERS' + SET_FOLDERS: 'SET_FOLDERS', + LOGOUT: 'LOGOUT' }; diff --git a/frontend/src/redux/actions.js b/frontend/src/redux/actions.js index 728f8663..c5bb8ae3 100644 --- a/frontend/src/redux/actions.js +++ b/frontend/src/redux/actions.js @@ -8,10 +8,8 @@ export function setAuthToken(token) { } export function endSession() { - //! @todo Flush complete state! return { - type: ActionTypes.SET_AUTH_SESSION, - session: null + type: ActionTypes.LOGOUT } } diff --git a/frontend/src/redux/reducers/index.js b/frontend/src/redux/reducers/index.js index fc62713a..3ea3f8ed 100644 --- a/frontend/src/redux/reducers/index.js +++ b/frontend/src/redux/reducers/index.js @@ -6,8 +6,9 @@ import timezones from './timezones'; import userProfile from './userProfile'; import ui from './ui'; import folders from './folders'; +import { ActionTypes } from '../actionTypes'; -export default combineReducers({ +const appReducer = combineReducers({ auth, dashboard, jobs, @@ -17,4 +18,12 @@ export default combineReducers({ folders }); -//! @todo Logout: Flush state +const rootReducer = (state, action) => { + if (action.type === ActionTypes.LOGOUT) { + return appReducer(undefined, action); + } else { + return appReducer(state, action); + } +} + +export default rootReducer;