Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
920 stars 167 forks source link

Can Roles.userIsInRole() be used in client? #319

Closed robguinness closed 3 years ago

robguinness commented 4 years ago

I am trying to update a project that uses alanning:roles 1.2.19 to version 3.2.2. For some reason after the upgrade, any client-side code that called Roles.userIsInRole(..) returns false. Also, Roles.getRolesForUser(..) returns an empty array.

Do I need to do something extra to make this info available to the client? I saw something in the README about publishing the role assignments to the client, but it wasn't clear if this is needed in order to make Roles.userIsInRole(..) and other similar APIs function properly on the client.

SimonSimCity commented 4 years ago

Well ... there seem to be a lot of people struggling with this.

Please follow the readme and tell me what is unclear: https://github.com/Meteor-Community-Packages/meteor-roles#migration-to-30

Reading through https://github.com/Meteor-Community-Packages/meteor-roles/issues/296 might also help, but then please tell me how the readme can be improved!

vladbalan commented 4 years ago

tl;dr: You need to publish Role assignments for the feature to work:

Meteor.publish(null, function () {
  if (this.userId) {
    return Meteor.roleAssignment.find({ 'user._id': this.userId });
  } else {
    this.ready()
  }
})
SimonSimCity commented 4 years ago

@vladbalan isn't this quoted from the readme ..?

SimonSimCity commented 3 years ago

Closing due to lack of feedback