Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

express/jade get current user in view

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.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

express/jade get current user in view

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×