title: How to show logged on username in NodeJS/ExpressJS/Passport?
body: <p>I want to display the username in case the user is logged in (<code>function 3</code>). Initially, I only had <code>function 1</code>. I've changed <code>function 1</code> into <code>function 2</code> in order to display the username of the logged in user. I am not sure if this is the right way to do this, because I don't know if I need parameters <code>res</code> and <code>next</code>, and function <code>next()</code>.  Any idea?</p>
  
  <p>I am using <code>NodeJS</code>, <code>ExpressJS</code> and <code>Passport</code></p>
  
  <p><strong>1.</strong></p>
  
  <pre><code>function isLoggedIn(req, res, next) {
    if (req.isAuthenticated()) {
      return next()
    } else {
      res.redirect('/login')
    }
  }
  </code></pre>
  
  <p><strong>2.</strong></p>
  
  <pre><code>function isLoggedIn(req, res, next) {
    if (req.isAuthenticated()) {
      return true
    }
    return false
  }
  </code></pre>
  
  <p><strong>3.</strong> </p>
  
  <pre><code>router.get('/', function(req, res) {
    if (isLoggedIn) {
      res.render('index', {
        username: req.user.username
      })
    } else {
      res.render('index')
    }
  })
  </code></pre>