title: Redux store changes when reload page
body: <p>I am implementing login with two different type of users using react redux.
  This is my login method:</p>
  
  <pre><code>export const login = (credentials) =&gt; (dispatch) =&gt;
      api.user.login(credentials).then(user =&gt; {
        localStorage.userJWT = user.token;
        localStorage.userEmail = user.email;
        localStorage.userId = user.id;
        localStorage.surname = user.surname;
        localStorage.type = user.type;
        dispatch(userLoggedIn(user));
  });
  </code></pre>
  
  <ol>
  <li>For the first type of user, I return from backend: token, email, id, surname.</li>
  <li>For the second type of user, I return from backend: token, email, id, type.</li>
  </ol>
  
  <p>I do some secured routes which the second type of user cannot access.
  So if the variable <code>surname</code> is returned, I define the specific route for that user.</p>
  
  <p>If <code>type</code> variable is returned, it shows properly everything in links and in redux store as well. However, if I reload the page, then it automatically changes variable <code>type</code> into <code>undefined surname</code>.</p>
  
  <p>This is where I am trying to save the redux state in store even if I reload the page.
      const store = createStore(
         rootReducer,
         composeWithDevTools(applyMiddleware(thunk))
       );</p>
  
  <pre><code> if(localStorage.userJWT &amp;&amp; localStorage.userEmail &amp;&amp; localStorage.userId &amp;&amp; localStorage.type){
     const user = { token: localStorage.userJWT, email: localStorage.userEmail, id: localStorage.userId, type: localStorage.type};
     store.dispatch(userLoggedIn(user));
   }
   if(localStorage.userJWT &amp;&amp; localStorage.userEmail &amp;&amp; localStorage.userId &amp;&amp; localStorage.surname){
     const user = { token: localStorage.userJWT, email: localStorage.userEmail, id: localStorage.userId, surname: localStorage.surname};
     store.dispatch(userLoggedIn(user));
   }
  </code></pre>
  
  <p>Can you please suggest why it is not following my if statement.
  Thank you in advance.</p>