title: What does passport.session() middleware do?
body: <p>I am building an authentication system using Passport.js using <a href="https://scotch.io/tutorials/easy-node-authentication-setup-and-local" rel="noreferrer">Easy Node Authentication: Setup and Local tutorial</a>.</p>
  
  <p>I am confused about what <code>passport.session()</code> does.</p>
  
  <p>After playing around with the different middleware I came to understand that <code>express.session()</code> is what sends a session ID over cookies to the client, but I'm confused about what <code>passport.session()</code> does and why it is required in addition to <code>express.session()</code>.</p>
  
  <p>Here is how I set up my application:</p>
  
  <p>// Server.js configures the application and sets up the webserver</p>
  
  <pre><code>//importing our modules
  var express = require('express');
  var app = express();
  var port = process.env.PORT || 8080;
  var mongoose = require('mongoose');
  var passport = require('passport');
  var flash = require('connect-flash');
  
  var configDB = require('./config/database.js');
  
  //Configuration of Databse and App
  
  mongoose.connect(configDB.url); //connect to our database
  
  require('./config/passport')(passport); //pass passport for configuration
  
  app.configure(function() {
  
      //set up our express application
  
      app.use(express.logger('dev')); //log every request to the console
      app.use(express.cookieParser()); //read cookies (needed for auth)
      app.use(express.bodyParser()); //get info from html forms
  
      app.set('view engine', 'ejs'); //set up ejs for templating
  
      //configuration for passport
      app.use(express.session({ secret: 'olhosvermelhoseasenhaclassica', maxAge:null })); //session secret
      app.use(passport.initialize());
      app.use(passport.session()); //persistent login session
      app.use(flash()); //use connect-flash for flash messages stored in session
  
  });
  
  //Set up routes
  require('./app/routes.js')(app, passport);
  
  //launch
  app.listen(port);
  console.log("Server listening on port" + port);
  </code></pre>