kahmali / meteor-restivus

REST APIs for the Best of Us! - A Meteor 0.9+ package for building REST APIs https://atmospherejs.com/nimble/restivus
MIT License
544 stars 117 forks source link

Role permissions don't work with meteor-roles v3 #305

Open leoncvlt opened 4 years ago

leoncvlt commented 4 years ago

I don't think the roleRequired options works anymore with the latest version of the alanning:roles package released a few months ago. As part of the update, they moved roles to a separate collection - I assume restivus still checks the roles on the user document, but since they are not there anymore it fails saying the user does not have the required permissions even if it does have the correct role.

A workaround for this is to check the role manually in the action:

Api.addRoute("private", {
  post: {
    authRequired: true,
    // roleRequired: "admin",
    action: function() {
      if (Roles.userIsInRole(this.userId, "admin")) {
        // user has admin role, do your things
        return 200;
      } else {
        return 401;
      }
    }
  }
});