title: Refreshing makes the user logged out in react, redux, nodejs and cookie based auth
body: <pre><code>router.post(&quot;/api/users/login&quot;, async (req, res) =&gt; {
    try {
      const user = await User.findbyCreds(req.body.email, req.body.password);
      const token = await user.createToken();
      res.cookie(&quot;token&quot;, token, {
        // maxAge: 60 * 60 * 1000,
        httpOnly: true,
        // secure: true,
        // sameSite: true,
      });
      res.send({ user, token });
    } catch (e) {
      res.status(400).send(e);
    }
  });
  </code></pre>
  <p>This is my login route on the server side (nodejs) and it work fine by making a cookie and passing it to the browser for all the further request's.</p>
  <pre><code>export const loginUser = (formValues) =&gt; async (dispatch) =&gt; {
    const user = await axios.post(&quot;/api/users/login&quot;, formValues);
    dispatch({
      type: &quot;LOGIN_USER&quot;,
      payload: user.data,
    });
    history.push(&quot;/&quot;);
  };
  </code></pre>
  <p>This is my redux action which calls the server forlogin request and it also works fine and it passes the user information to the redux state which i use further.</p>
  <p>The problem is when i refresh my webpage redux state gets empty and the value stored in the user of redux sate goes null while i want it to ressist so that user should not login again &amp; again after refreshes. Moreover my cookie is still there in browser after i refresh.</p>