Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
fix(#90): redux store is reset on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Gasser committed Apr 1, 2019
1 parent b975c90 commit 11dc279
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/redux/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const AppStatus = {

// action types
export const APP_IDLE = 'APP_IDLE';
export const APP_RESET = 'APP_RESET';

const APPLICATION_STATUS_SET = 'APPLICATION_STATUS_SET';

Expand All @@ -29,6 +30,10 @@ export const appIdle = () => ({
type: APP_IDLE,
});

export const appReset = () => ({
type: APP_RESET,
});

const applicationWillLoad = () => ({
type: APPLICATION_STATUS_SET,
payload: AppStatus.APPLICATION_WILL_LOAD,
Expand Down
1 change: 1 addition & 0 deletions src/redux/auth/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ describe('auth: complex action test suite', () => {

const expectedActions = [
__testables__.authLogOut(message),
reduxApplication.appReset(),
];

// set localStorage and sessionStorage
Expand Down
5 changes: 4 additions & 1 deletion src/redux/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import hocReducer, { hocAsyncAction, hocCreateTypes } from '../HOC';

import { authRememberSelector, authUsernameSelector } from './selectors';

import { loadApplicationAuthenticated } from '../application';
import { loadApplicationAuthenticated, appReset } from '../application';

// action def
export const AUTH_LOG_IN = 'AUTH_LOG_IN';
Expand Down Expand Up @@ -101,6 +101,9 @@ export const logOutUser = (message, broadcast = true) => (dispatch) => {
// fire logout action
dispatch(authLogOut(message));

// clear state
dispatch(appReset());

// clean up state
try {
console.log('clear local & session storage');
Expand Down
15 changes: 13 additions & 2 deletions src/redux/rootReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global requestAnimationFrame */
import { combineReducers } from 'redux';

import applicationReducer from './application';
import applicationReducer, { APP_RESET } from './application';
import authReducer from './auth';
import imagesReducer from './images';
import labelsReducer from './labels';
Expand All @@ -18,4 +18,15 @@ const reducers = combineReducers({
user: userReducer,
});

export default reducers;
const rootReducer = (state, action) => {
let usedState = state;

// handle reset
if (action.type === APP_RESET) {
usedState = undefined;
}

return reducers(usedState, action);
}

export default rootReducer;

0 comments on commit 11dc279

Please sign in to comment.