title: How to set cookies express, react.js
body: <p>I am building a login system using express for <code>node.js</code> and <code>react.js</code>. In my back-end when a user logs in, it creates a cookie. When I go to Network &gt; Login I can see this:</p>
  <p>Set-Cookie:</p>
  <pre><code>user_id=s%3A1.E%2FWVGXrIgyXaM4crLOoxO%2Fur0tdjeN6ldABcYOgpOPk; Path=/; HttpOnly; Secure
  </code></pre>
  <p>But when I go to Application &gt; Cookies &gt; http://localhost:3000, there is nothing there.  I believe that is because I am not allowing credentials to go through correctly when I do a post request from the client side. How do I go about this? Please, let me know if I can improve my question in any way.</p>
  <pre class="lang-js prettyprint-override"><code>//Login back-end
  router.post('/login', (req, res, next) =&gt; {
      if(validUser(req.body)) {
          User
              .getOneByEmail(req.body.email)
              .then(user =&gt; {
                  if(user) {
                      bcrypt
                          .compare(req.body.password_digest, user.password_digest)
                          .then((result) =&gt; {
                              if(result) {
                                  const isSecure = process.env.NODE_ENV != 'development';
  
                                  res.cookie('user_id', user.id, {
                                      httpOnly: true,
                                      secure: isSecure,
                                      signed: true
                                  })
                                  res.json({
                                      message: 'Logged in'
                                  });
                              } else {
                                  next(new Error('Invalid Login'))
                              }
                          });
                  } else {
                      next(new Error('Invalid Login'))
                  }
              });
      } else {
          next(new Error('Invalid Login'))
      }
  });
  
  //Allow CORS index.js
  app.use(
  cors({
      origin: &quot;http://localhost:3000&quot;,
      credentials: true
  })
  );
  
  //Login client side (React.js)
  loginUser(e, loginEmail, password) {
  e.preventDefault();
  
  let email = loginEmail;
  let password_digest = password;
  let body = JSON.stringify({ email, password_digest });
  
  fetch(&quot;http://localhost:5656/api/login&quot;, {
      method: &quot;POST&quot;,
      headers: {
      &quot;Content-Type&quot;: &quot;application/json&quot;
      },
      credentials: &quot;include&quot;,
      body
  })
      .then(response =&gt; response.json())
      .then(user =&gt; {
      console.log(user);
      });
  }
  
  </code></pre>