title: Express.js require session to access particular routes
body: <p>I have an app where certain pages require that the user be logged in.</p>
  
  <p>I am not sure if there is something built in for this, but what I have for doing this is as follows:</p>
  
  <pre><code>app.use((req, res, next) =&gt; {
    if (req.session.username) {
      app.get('/project/create', projectCtrl.create)
      app.get('/project/create/save', projectCtrl.save)
    } else {
      return res.redirect('/')
    }
    next()
  })
  </code></pre>
  
  <p>Is this the correct way of doing this, or is there a better way in express? The way I am doing it kind of feels a little hacky.</p>