title: Express server not setting cookies
body: <p>I have been trying to figure out what is wrong with this code for setting cookies in the server after login authorization from the client. Currently, it will print to the console en empty object that represents cookies. Once the backend server has verified the login it sets the cookies like this:        </p>
  
  <pre><code>// UserController.js (server-side)
  
      res.cookie('token', token )
         .cookie('username', username)
         .status(201)
         .send(username)
  </code></pre>
  
  <p>This then returns back to this function which redirects it a new page </p>
  
  <pre><code>/// Login.js (client-side)
  
    const login = async () =&gt; {
        var token = params.get("token")
  
        const config = {
          method: 'POST', 
          url: url + "/users/fbLogin", 
          headers: {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "http://localhost:3000"
          }, 
          data: {
            fb_id: fb_id, 
            token: token, 
          }
        }
  
        var res = await axios(config)
        if(res.status === 201) {
          window.location.assign(`${client_url}/home?user=${res.data}`);
        }
    } 
  
  </code></pre>
  
  <p>When the page is redirected it sends a get request back to the server like so: </p>
  
  <pre><code>// UserHome.js
  
  function validateUser(username){
  
      // axios.defaults.withCredentials = true
      const config = {
          method: 'GET', 
          url: url + '/users/auth', 
          // withCredentials: 'true', 
          headers: {
              "Content-Type": "application/json",
              'Access-Control-Allow-Credentials': true,
              "Access-Control-Allow-Origin": "http://localhost:3000"
          }, 
          data: {
              username: username
          }, 
      }
      try {
  
          var res = axios(config)
  
      } catch(err) {
          console.log(err)
      }
  
  }
  </code></pre>
  
  <p>this request is handled by this function: </p>
  
  <pre><code>// UsersController.js 
  
  UsersController.auth = async function(req, res) {
      console.log(req.cookies)
  }
  </code></pre>
  
  <p>which currently prints out this: [Object: null prototype] {}</p>
  
  <p>Does anyone know what I am clearly doing wrong? I am testing it also in Chrome and Safari and having the same issues. </p>
  
  <p>The express setup: </p>
  
  <pre><code>
  const express = require('express');
  const bodyParser = require('body-parser');
  const app = express(); 
  const cors = require('cors');
  const api =  require('./api/index.js'); 
  const passport = require('passport')
  const cookieParser = require("cookie-parser");
  var cookieSession = require('cookie-session')
  
  
  // setup the connection
  const port = process.env.PORT || 5000;
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  // use it before all route definitions
  app.use(cors({origin: 'http://localhost:3000'}));
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  app.use(cookieSession({
      auth: 'session', 
      keys: 'secret', 
      maxAge: 900000,
      httpOnly: false, 
      sameSite: false, 
      overwrite: true
  }))
  
  app.use(cookieParser());
  app.use('/', api); 
  
  app.listen(port, () =&gt; console.log(`Listening on port ${port}`));
  
  
  </code></pre>