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

Why my custom policy is not recognised in Sails JS

Why my custom policy is not recognised in Sails JS

Problem

Following this screencast, I've created a Policy in api/policies/flash.js. I then tried to use this policy in config/policies where at the beginning of the file I've used '*':flash so all my controllers would use this policy, however every time I tried to start Sails after this I got the error that flash is undefined. The code I've used in the aforementioned policy is this:

module.exports = function(req, res, next) {

res.locals.flash = {};

if(!req.session.flash) return next();

res.locals.flash = _.clone(req.session.flash);

// Clear flash
req.session.flash = {};

next();

};

I've also tried (like in the example in config/policies.js) module.exports = function flash(req, res, next)... and it also got the same error. In the screencast mentioned above the same steps did work perfectly. I've checked and rechecked to make it wasn't something I missed and couldn't find anything. I imagine it might be a version issue.

Can anyone clarify what I'm doing wrong?

Many thanks

Problem courtesy of: WagnerMatosUK

Solution

Everything seems good except that in your config/policies.js it should be 'flash' with apostrophes:

module.exports.policies = {
  '*': 'flash'
};
Solution courtesy of: bredikhin

Discussion

View additional discussion.



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

Share the post

Why my custom policy is not recognised in Sails JS

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×