I am using mean.io but for my reasons I cut out all the angular it has and replace with knockout.js. Also I want to notice that my application is not single page. I render pages from different views and require for each require.js module with knockout business logic.

That's about app I deal with and here is my problem.

For example if user is logged in I want to show his name in the header of my app. So, I need to set express app.locals after passport creates user session. The problem is I have no idea where does it happen. I find passport initialization, but don't know how to ger user name without using req.user object. So, what is the best way of doing it

有帮助吗?

解决方案

Use a middleware.

app.use(function(req, res, next) {
    req.user && (app.locals.user = req.user)
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top