Using Passport.js and Express for multiple projects now, I have noticed myself doing this over and over again, namely specifying { user: req.user }
explicitly f
You could use a simple middleware for that:
app.use(function(req, res, next) {
res.locals.user = req.user;
next();
});
This will make a user
variable available in all templates, provided that req.user
is populated. Make sure that you declare that middleware after you declare the passport.session
middleware, but before any routes.