mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Clear store after logout
This commit is contained in:
parent
f4a3dcad5e
commit
b76cbadca3
3 changed files with 17 additions and 2 deletions
|
|
@ -20,6 +20,10 @@ export const SIGNUP_REQUEST = 'app/Auth/SIGNUP_REQUEST';
|
|||
export const SIGNUP_SUCCESS = 'app/Auth/SIGNUP_SUCCESS';
|
||||
export const SIGNUP_ERROR = 'app/Auth/SIGNUP_ERROR';
|
||||
|
||||
// Generic user_logout action that can be handled elsewhere
|
||||
// E.g. src/reducers.js clears store as a consequence
|
||||
export const USER_LOGOUT = 'app/USER_LOGOUT';
|
||||
|
||||
// ================ Reducer ================ //
|
||||
|
||||
const initialState = {
|
||||
|
|
@ -110,6 +114,8 @@ export const signupRequest = () => ({ type: SIGNUP_REQUEST });
|
|||
export const signupSuccess = () => ({ type: SIGNUP_SUCCESS });
|
||||
export const signupError = error => ({ type: SIGNUP_ERROR, payload: error, error: true });
|
||||
|
||||
export const userLogout = () => ({ type: USER_LOGOUT });
|
||||
|
||||
// ================ Thunks ================ //
|
||||
|
||||
export const authInfo = () =>
|
||||
|
|
@ -150,6 +156,7 @@ export const logout = () =>
|
|||
.logout()
|
||||
.then(() => dispatch(clearCurrentUser()))
|
||||
.then(() => dispatch(logoutSuccess()))
|
||||
.then(() => dispatch(userLogout()))
|
||||
.catch(e => dispatch(logoutError(e)));
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import reducer, {
|
|||
signupRequest,
|
||||
signupSuccess,
|
||||
signupError,
|
||||
userLogout,
|
||||
} from './Auth.duck';
|
||||
|
||||
// Create a dispatch function that correctly calls the thunk functions
|
||||
|
|
@ -276,6 +277,7 @@ describe('Auth duck', () => {
|
|||
[logoutRequest()],
|
||||
[clearCurrentUser()],
|
||||
[logoutSuccess()],
|
||||
[userLogout()],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { combineReducers } from 'redux';
|
||||
import { USER_LOGOUT } from './ducks/Auth.duck';
|
||||
import * as globalReducers from './ducks';
|
||||
import * as pageReducers from './containers/reducers';
|
||||
|
||||
|
|
@ -9,8 +10,13 @@ import * as pageReducers from './containers/reducers';
|
|||
* which is page specific.
|
||||
* Future: this structure could take in asyncReducers, which are changed when you navigate pages.
|
||||
*/
|
||||
const createReducer = function createReducer() {
|
||||
return combineReducers({ ...globalReducers, ...pageReducers });
|
||||
const appReducer = combineReducers({ ...globalReducers, ...pageReducers });
|
||||
|
||||
const createReducer = () => {
|
||||
return (state, action) => {
|
||||
const appState = action.type === USER_LOGOUT ? undefined : state;
|
||||
return appReducer(appState, action);
|
||||
};
|
||||
};
|
||||
|
||||
export default createReducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue