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

Dynamic sidebars with Node.js, Express.js and Jade

Dynamic sidebars with Node.js, Express.js and Jade

Problem

I'm trying to write a dynamicHelper for Jade to check if a user is allowed to access a resource before actually accessing it. I have the module to perform the checks which returns true or false when called with the url and username of the resource to be accessed, but I can't get the helper working with parameters?

dummy view:

if(hasAccess.check("/url", "username") == true)
  li access
else
  li no-access

Helper:

app.dynamicHelpers({
  hasAccess: function() {
    return access;
  }
});

Access-function:

var access = function() {
  return {
    check: function(url, user) {
      return mymodule.hasAccess(url, user);
    }
  };
};

I tried to get it done with this answer, but no luck so far.

Problem courtesy of: Patrick

Solution

There are a couple of things wrong there (if I understand it correctly)

  • Your hasAccess function isn't accepting any parameters
  • hasAccess is also just returning a reference to the access function, not calling it
  • the access function doesn't accept any parameters either

It's possible that what you're trying to do would work using

app.dynamicHelpers({
  hasAccess: access().check
});

But i haven't run the code, so I may be completely wrong.

Good luck :)

Solution courtesy of: arnorhs

Discussion

View additional discussion.



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

Share the post

Dynamic sidebars with Node.js, Express.js and Jade

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×