added logout functions to clear store
This commit is contained in:
@@ -15,3 +15,9 @@ export const setAccountDetails = (accountDetails) => (dispatch) => {
|
||||
accountDetails: accountDetails,
|
||||
});
|
||||
};
|
||||
|
||||
export const setLogout = () => (dispatch) => {
|
||||
return dispatch({
|
||||
type: "USER_LOGOUT",
|
||||
});
|
||||
};
|
||||
|
||||
+14
-3
@@ -9,9 +9,10 @@ import LPAData from "./lpa/reducer";
|
||||
import accountDetails from "./accountDetails/reducer";
|
||||
import { reducer as formReducer } from "redux-form";
|
||||
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
|
||||
import storage from "redux-persist/lib/storage";
|
||||
|
||||
//COMBINING ALL REDUCERS
|
||||
const combinedReducer = combineReducers({
|
||||
const appReducer = combineReducers({
|
||||
search,
|
||||
searchResultsObj,
|
||||
formData,
|
||||
@@ -21,6 +22,16 @@ const combinedReducer = combineReducers({
|
||||
form: formReducer,
|
||||
});
|
||||
|
||||
const combinedReducer = (state, action) => {
|
||||
if (action.type === "USER_LOGOUT") {
|
||||
// for all keys defined in your persistConfig(s)
|
||||
storage.removeItem("persist:acp");
|
||||
// storage.removeItem('persist:otherKey')
|
||||
return appReducer(undefined, action);
|
||||
}
|
||||
return appReducer(state, action);
|
||||
};
|
||||
|
||||
const reducer = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case HYDRATE:
|
||||
@@ -77,7 +88,7 @@ const makeStore = ({ isServer }) => {
|
||||
const storage = require("redux-persist/lib/storage").default;
|
||||
|
||||
const persistConfig = {
|
||||
key: "nextjs",
|
||||
key: "acp",
|
||||
whitelist: [
|
||||
"search",
|
||||
"searchResults",
|
||||
@@ -87,7 +98,7 @@ const makeStore = ({ isServer }) => {
|
||||
"accountDetails",
|
||||
"form",
|
||||
],
|
||||
storage,
|
||||
storage: storage,
|
||||
stateReconciler: autoMergeLevel2, // if needed, use a safer storage
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user