How to read the roles array from Meteor.users collection in Client?

后端 未结 2 724
终归单人心
终归单人心 2021-01-21 21:07

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

2条回答
  •  春和景丽
    2021-01-21 21:21

    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');
    

提交回复
热议问题