service - hooked policies returns an empty array, sails -


im tryng make works 2 hooked policies, doesnt. each of these works, , both return next(), then, when supposed pass controller, return empty array instead of list of devices here's config/policies.js

module.exports.policies = {    '*': ['isauthorized'], // resctricted here   'usercontroller': {     'create': true // dont need authorization here, allowing public access   },    'authcontroller': {     '*': true // dont need authorization here, allowing public access   },    'device' : {     'find' : ['isauthorized', 'isowner']   }  }; 

this policies. policies/isauthorized.js

module.exports = function (req, res, next) {   var token;    if (req.headers && req.headers.authorization) {     var parts = req.headers.authorization.split(' ');     if (parts.length == 2) {       var scheme = parts[0],         credentials = parts[1];        if (/^bearer$/i.test(scheme)) {         token = credentials;       }     } else {       return res.json(401, {err: 'format authorization: bearer [token]'});     }   } else if (req.param('token')) {     token = req.param('token');     // delete token param not mess blueprints     delete req.query.token;   } else {     return res.json(401, {err: 'no authorization header found'});   }    // aqui se consulta la funcion verify del archivo jwtoken.js q esta disponible dentro de services   jwtoken.verify(token, function (err, token) {     if (err) return res.json(401, {err: 'invalid token!'});     req.token = token; // decrypted token or payload provided     next();   }); }; 

and policies/isowner.js, 1 test moment

module.exports = function(req, res, next) {    // user allowed, proceed next policy,   // or if last policy, controller   if (req.param('pass') == 'secret') {     return next();   }    // user not allowed   // (default res.forbidden() behavior can overridden in `config/403.js`)   return res.forbidden('you not permitted perform action.'); }; 

i hope helpfull , sorry bad english.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -