generators/app/templates/server/lib/auth(auth)/auth.service.js
function hasRole(roleRequired) {
  if (!roleRequired) {
    throw new Error('Required role needs to be set');
  }

  return compose()
    .use(isAuthenticated())
    .use(function meetsRequirements(req, res, next) {
      if (roles.hasRole(req.userInfo.role, roleRequired)) {
        next();
      } else {
        res.forbidden();
      }
    });
}
function hasRole(roleRequired) {
  if (!roleRequired) {
    throw new Error('Required role needs to be set');
  }

  return compose()
    .use(isAuthenticated())
    .use(function meetsRequirements(req, res, next) {
      if (roles.hasRole(req.userInfo.role, roleRequired)) {
        next();
      } else {
        res.forbidden();
      }
    });
}
function hasRole ( roleRequired ) { if ( ! roleRequired ) { throw new Error ( 'Required role needs to be set' ) ; } return compose ( ) . use ( isAuthenticated ( ) ) . use ( function meetsRequirements ( req , res , next ) { if ( roles . hasRole ( req . userInfo . role , roleRequired ) ) { next ( ) ; } else { res . forbidden ( ) ; } } ) ; }
Checks if the user role meets the minimum requirements of the route, sets
the response status to FORBIDDEN if the requirements do not match.
@param {String} roleRequired - Name of the required role
@return {ServerResponse}
Checks if the user role meets the minimum requirements of the route sets the response status to FORBIDDEN if the requirements do not match .