title: withCredentials = true is not working even after using CORS
body: <p>I am using Vue@CLI and ExpressJs , with Passport.js for authentication. I have written the following code for setting local strategy for authentication using email &amp; password. I have tested the code in postman and it is working fine, cookies are stored successfully for the session.</p>
  
  <p>But when I am fetching the Http Request from the client, i.e. VueJs then it stores the session but when I refresh the browser, the session is disappeared. I</p>
  
  <p>I am just a beginner in Web Dev and I have tried every solution that was provided on internet, like using axios.defaults.withCredentials = true and passing withCredentials: true with the requests.</p>
  
  <p>Please help me I am blocked....</p>
  
  <p>users.js</p>
  
  <blockquote>
  <pre><code>router.post('/login', async (req, res, next) =&gt; {   
  
  passport.authenticate('local', {
      session: false
      }, (err, user, info) =&gt; {
          if(err) return next(err)
          if (!user) { 
              return res.send("LogIn Failed") 
          }
          req.logIn(user, function(err) {
          if (err) { return next(err) }  
          req.session.user = "hey"
          console.log(req.session)
          res.send("Log In Success")              
  
      })
  })(req, res, next)router.post('/login', async (req, res, next) =&gt; {   
  
  passport.authenticate('local', {
      session: false
      }, (err, user, info) =&gt; {
          if(err) return next(err)
          if (!user) { 
              return res.send("LogIn Failed") 
          }
          req.logIn(user, function(err) {
          if (err) { return next(err) }  
          req.session.user = "hey"
          console.log(req.session)
          res.send("Log In Success")              
  
      })
  })(req, res, next)  
   })
  </code></pre>
  </blockquote>
  
  <p>app.js</p>
  
  <pre><code>const express = require('express')
  const app = express()
  const morgan = require('morgan')
  const bodyParser = require('body-parser')
  const mongoose = require('mongoose')
  const session = require('express-session')
  const passport = require('passport')
  const cors = require('cors')
  const MongoStore = require('connect-mongo')(session);
  const cookieParser = require('cookie-parser')
  
  //Config Passport
  require('./config/passport')(passport)
  
  //Routes
  const projectRoutes = require('./api/routes/projects')
  const userRoutes = require('./api/routes/users')
  
  
  //App Middlewares
  app.use(morgan('dev'))
  app.use(cors())
  app.use(bodyParser.urlencoded({ extended: false }))
  app.use(bodyParser.json())
  app.use(cookieParser())
  
  
  //Express Session
  app.use(session({
    secret: 'secret-key',
    resave: false,
    saveUninitialized: true,
    store: new MongoStore({ 
        mongooseConnection: mongoose.connection,
         ttl: 24 * 60 * 60 
     }),
    cookie: {
      maxAge: 24 * 60 * 60 * 1000
  
      }
  }))
  
  //Passport Middleware
  app.use(passport.initialize());
  app.use(passport.session());
  
  
  //Route Middlewares
  app.use('/project', projectRoutes)
  app.use('/user', userRoutes)
  
  //404 Not Found
  app.use((req, res, next) =&gt; {
      const error = new Error('Not Found')
      error.status = 404
      next(error)
  })
  
  //Errors
  app.use((error, req, res, next) =&gt; {
      res.status(error.status || 500)
      res.json({
          error: {
              message: error.message
          }
      })
  })
  
  //Database Connection
  mongoose.connect('mongodb://localhost/database', { useNewUrlParser: true },)
      // mongoose.Promise = global.Promise;
  
  
  
  module.exports = app
  </code></pre>
  
  <p>and I am passing the following request:</p>
  
  <pre><code>this.result = await axios.post('http://localhost:3000/user/login', {               
         email: this.email,
         password: this.password              
  },
  {withCredentials: true});  
  </code></pre>