title: How to configure express and passport with multiple sessions
body: <p>I need to implement a HTTP server which supports separate session handling with passport. The reason is that I need authentication for 2 entities: my customers (accounts) and their customers (users) and my idea was to use an own secure "space" for that: own session middleware, different session properties, own passport instance.</p>
  
  <p>It's working fine if I just use a session store for the accounts but not for users with this code:</p>
  
  <pre><code>const express = require('express')
  const session = require('express-session')
  const Passport = require('passport').Passport
  const userPassport = new Passport()
  const accountPassport = new Passport()
  // add passport strategies
  
  const app = express()
  app.use(session({
    secret: config.session.secret,
    //store: accountSessionStore,
    resave: true,
    saveUninitialized: true,
  }))
  
  app.use(accountPassport.initialize({ userProperty: 'account' }))
  app.use(accountPassport.session())
  
  app.use(userPassport.initialize({ userProperty: 'user' }))
  </code></pre>
  
  <p>As soon I add this line <code>app.use(userPassport.session())</code> at the end it breaks: login flow for accounts doesn't work anymore. It seems that express session middleware cannot handle multiple passport instances and the last call is overwriting the instance.</p>
  
  <p>Wrapping the accounts and customers into an own instance like this:</p>
  
  <pre><code>const app1 = express()
  // register stuff for accounts
  const app2 = express()
  // register stuff for users
  const rootApp = express()
  rootApp.use(app1)
  rootApp.use(app2)
  </code></pre>
  
  <p>didn't work and using an own HTTP server (and an additional port) seems a bit overkill.</p>