title: How to handle unauthorized requests with nodejs/passport
body: <p>As per <a href="http://passportjs.org/guide/authenticate/" rel="nofollow noreferrer">the documentation</a>, if I was handling authentication requests like so, I would be able to capture successful attempts.</p>
  <pre><code>app.post('/login',
    passport.authenticate('local'),
    function(req, res) {
      // If this function gets called, authentication was successful.
      // `req.user` contains the authenticated user.
      res.redirect('/users/' + req.user.username);
    });
  </code></pre>
  <p>But, like the documentation says:</p>
  <blockquote>
  <p><em>By default, if authentication fails, Passport will respond with a 401 Unauthorized status, and any additional route handlers will not be invoked.</em> If authentication succeeds, the next handler will be invoked and the req.user property will be set to the authenticated user.</p>
  </blockquote>
  <p>How can I handle the unauthorized login attempt?</p>
  <p>I know I can handle it with custom middleware but is there a better way?</p>