title: Express & Passport with multiple subdomains
body: <p>I'm merging two little apps into one, that is supposed to be accessed via two subdomains. To do so I'm using the module "express-subdomain". I'm trying to use Passport so when a user logs in in the first app, he is logged in in both apps. However using <code>req.isAuthenticated()</code> I can indeed login in the "first" app, but then I'm not in the "second" one.</p>
  
  <p>I'm searching for any solution to have a passport authentification in the first subdomain and being logged in in the second one, including keeping two disctinct apps if needed.</p>
  
  <p>Assuming that passport is correctly configured for a local strategy, as well as the routers and the rest of the app. Here is what it looks like :</p>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>// &lt;- requires etc
  
  var passport = require('./configurePassport.js')(require('passport'));
  
  var app = express();
  
  app.use(cookieParser());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(expressSession({
      secret: 'bestSecretEver',
      resave: false,
      saveUninitialized: false
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  // and others
  
  var firstRouter = express.Router();
  firstRouter.use('/public', express.static(__dirname + '/first/public'));
  firstRouter.use(favicon(__dirname + '/first/public/favicon.ico'));
  
  // &lt;- setting first router's GET, POST etc
  
  app.use(subdomain('sub1', firstRouter)); // for sub1.example.com
  
  var secondRouter = express.Router();
  secondRouter.use('/public', express.static(__dirname + '/second/public'));
  secondRouter.use(favicon(__dirname + '/second/public/favicon.ico'));
  
  // &lt;- setting second router's GET, POST etc
  
  app.use(subdomain('sub2', secondRouter)); // for sub2.example.com
  </code></pre>
  
  <p>Any idea ?</p>