title: How can you define multiple isAuthenticated functions in Passport.js?
body: <p>I am building an app using Express/Node.js with Passport.js(passport-local) &amp; Mongoose.</p>
  
  <p>There are two kind of users:</p>
  
  <ol>
  <li>regular users (they login using <code>/user-login</code> page and passport strategy <code>'local-user-login'</code>; regular users are stored in "Users" MongoDB collection)</li>
  <li>admins (they login using <code>/admin-login</code> page and passport strategy <code>'local-admin-login'</code>; admins are stored in "Admins" MongoDB collection)</li>
  </ol>
  
  <p>I also have 2 pages: <code>/user_home</code> (needs to be accessible to <em>logged regular users only</em>) and <code>/admin_home</code> (for <em>logged admins only</em>)</p>
  
  <p>Route for <code>/user_home</code>:</p>
  
  <pre><code>app.get('/user_home', isLoggedIn, function(req, res) {
      // render the page
  });
  
  function isLoggedIn(req, res, next) {
      if (req.isAuthenticated())
          return next();
      res.redirect('/login');
  }
  </code></pre>
  
  <p>If I log in as an admin and try to access <code>/user_home</code>, it doesn't allow me, which is fine. My question is: <strong>how can I define another "<code>isLoggedIn</code>" function that checks if I am logged in as an admin rather than a regular user?</strong> Ideally I would like to have a function "isLoggedInAsUser" and another one "isLoggedInAsAdmin".</p>
  
  <p>So far I tried defining the <code>/admin_home</code>  route the same way:</p>
  
  <pre><code>app.get('/admin_home', isLoggedIn, function(req, res) {
      // render the page
  });
  </code></pre>
  
  <p>But it's obvious why it doesn't work. The code doesn't know that I want it to check if it's an admin rather than a regular user.</p>