If you set res.locals.loggedin to the /login route, as hexacanide suggests, this locale will not be accessible on the route to /foo . res.locals is cleared for each request.
instead, you could put this above other routes:
app.all('*', function(req, res, next){ if(req.user){ res.locals.loggedin = true; res.locals.currentuser = req.user; }; next(); });
Pretty sure that if you change req.user during your route, the res.locals.currentuser that you installed earlier will not be updated to be the new req.user . but not sure about that.
In fact, I use the custom render function for each page where I create the template, it looks like this:
function myRender(templateName){ return function(req, res){ res.locals.currentuser = req.user || null; res.render(templateName); }; };
and I use it as follows:
app.get('/foo' , function(req, res, next){ res.locals.bar = req.query['bar'] || ""; console.log('passing request to myRender middleware'); next(); } , myRender('foo-jade-template') )
This has an advantage only when installing res.locals.currentuser , when I am ready to do something, and not before completing my route. Therefore, if I modify req.user , you will have the latest version at the time of rendering.
Plato
source share