title: Resetting redux state on logout
body: <p>I am trying to deal with the problem, addressed, in general in an earlier thread - <a href="https://stackoverflow.com/questions/35622588/how-to-reset-the-state-of-a-redux-store">How to reset the state of a Redux store?</a> - the need to reinitialize/invalidate the entire redux store on user logout.</p>
  
  <p>In my case, however, something is still missing. I am using Redux with ConnectedRouter and I tried to do the following.</p>
  
  <p>Define the rootReducer as:</p>
  
  <pre><code>export default history =&gt; 
    combineReducers({
      router: connectRouter(history),
      user,
      manager,
      vendor
      // rest of your reducers
    });
  </code></pre>
  
  <p>Then I do <code>configureStore</code>, importing the above  as <code>createRootReducer</code>:</p>
  
  <pre><code>const configureStore = (initialState = {}, history) =&gt; {
    let composeEnhancers = compose;
    const composeWithDevToolsExtension =
      window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
    const enhancers = [];
    const middleware = [sagaMiddleware, thunk, routerMiddleware(history)];
    if (typeof composeWithDevToolsExtension === 'function') {
      composeEnhancers = composeWithDevToolsExtension;
    }
    const store = createStore(
      createRootReducer(history), // root reducer with router state
      initialState,
      composeEnhancers(applyMiddleware(...middleware), ...enhancers)
    );
    store.runSaga = sagaMiddleware.run;
    store.subscribe(() =&gt; {
      const state = store.getState();
      const { session } = state['user'];
      if (!session) {
        console.log('no valid session');
        initialState = undefined;
      } else {
        const { token } = session;
        const decodedToken = jwt_decode(token);
        const { exp } = decodedToken;
        const now = new Date();
        if (exp &gt; now.getTime()) {
          console.warn('token expired');
          initialState = undefined;
        } else {
          console.log('token valid');
        }
      }
    });
    return store;
  };
  export default configureStore({}, history);
  </code></pre>
  
  <p>The idea is that <code>initialState = undefined;</code> should reset my state. It is not working for me though.</p>
  
  <p>Where would be the correct place to do this, given that I am using the <code>ConnectedRouter</code> and passing the <code>history</code> object to it?</p>