express/jade get current user in view
Problem
I have a simple nodejs/express application by this example. In that view there is checking everyauth.loggedIn variable, but in my application I don't use everyauth module I use the following code instead:
req.session.auth = user;
How can I get access to req.session.auth in a view in this case?
Problem courtesy of: Erik
Solution
You'll need to use a dynamicHelper
to expose anything in the session object (or the session object itself). You can do something like this in your app.js:
app.dynamicHelpers({
auth: function(req, res){
return req.session.auth;
}
});
Then in your views, you will have an auth
variable that points to the session object. For example:
You are logged in as
Solution courtesy of: Scott Anderson
Discussion
View additional discussion.