I use the package: alanning/meteor-roles
I am building a simple UI for Admin to manage other users roles. A user can have more than one role, I am using checkbox to choo
You need to publish the roles
key:
Server:
Meteor.publish('roles',() => {
if ( Roles.userIsInRole(this.userId,['Admin']) {
return Meteor.users.find({},{fields: {roles: 1}});
} else this.ready();
});
And subscribe to that on the client:
Meteor.subscribe('roles');
By default Meteor does not publish data outside profile
for Meteor.users
collection, except for the current user. The rationale is to make sure sensitive data is always hidden.
If the autopublish package is installed, information about all users on the system is published to all clients. This includes*
username
,profile
, and any fields in services that are meant to be public (egservices.facebook.id
,services.twitter.screenName
). Additionally, when using autopublish more information** is published for the currently logged in user, including access tokens.
(source: https://docs.meteor.com/api/accounts.html#Meteor-users)
* means other fields are excluded, therefore roles
is not published by autopublish
.
** this includes roles
field for the current user.
That is why your code works only for the current user.
Therefore you just need to setup a publication (and subscribe to it) that explicitly sends the roles field of your users to the client:
Meteor.publish('usersRoles', function () {
return Meteor.users.find(mySelector, {
fields: {
roles: 1
}
});
});