title: Passport local protect sub-pages if user didn't login
body: <p>I follow this <a href="http://mherman.org/blog/2015/01/31/local-authentication-with-passport-and-express-4/#comment-2823871815" rel="nofollow noreferrer">tutorial</a> but has trouble 'protecting' my pages if the user did not login. I want to redirect them to login page.</p>
  
  <p>I've tried to do a middleware in app.js</p>
  
  <pre><code>app.use(function(req, res, next){
      if(!req.user){
        return res.redirect('/login_');
      }
      next();
    }
  })
  </code></pre>
  
  <p>but I got an infinite loop.</p>
  
  <p><a href="https://i.stack.imgur.com/5q63Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5q63Y.png" alt="enter image description here"></a></p>