title: How to pass user data into all all views?
body: <p>I can't work out how best to pass user details (email, name, etc.) to 'logged in' views (I'm using jade).</p>
  
  <p>I'm using passport and have access to <code>session.passport.user</code> in my views but only the user's _id is saved on here, and i've been told it would be bad security practice to persist it locally in the session cookie.</p>
  
  <p>I don't want to have to pass a user object to <code>res.render</code> on each controller that I need the user.</p>
  
  <p>this is how i have sessions setting up locally</p>
  
  <pre><code>app.use(function (req, res, next) {
    res.locals.session = req.session;
    next(null, req, res);
  });
  </code></pre>
  
  <p>and this is my middleware to check if a user is logged in</p>
  
  <pre><code>function isLoggedIn(req, res, next) {
    // if user is authenticated in the session, carry on 
    if (req.isAuthenticated()) {
      return next();
    }
  
    // if they aren't redirect them to the home page
    res.redirect('/');
  }
  </code></pre>
  
  <p>I have looked at dynamic helpers but I'm using express v3.0.0rc4.</p>