Meteor User Property

前端 未结 2 1492
说谎
说谎 2021-02-10 09:40

I\'d like to be able to mark users as \"admin\" in the Meteor auth system, and allow that user to do special things, as well as show some gui elements I wouldn\'t show if they w

相关标签:
2条回答
  • 2021-02-10 09:44

    To anyone in the future, simply assign the value in the users table in the database. You can publish additional fields to the user using the following:

    Meteor.publish("userData", function () {
         return Meteor.users.find({_id: this.userId}, {fields: {'admin': 1}});
    });
    

    And on the client:

    Meteor.subscribe("userData");
    

    Poof. Straight from the documentation.

    0 讨论(0)
  • 2021-02-10 10:10

    You can also add properties in "profile" attribute of the user. profile attribute is alrealy populated to client side :

    Meteor.users.update({_id: userId}, {$set: {'profile.admin': 1}});
    
    //on client side
    Meteor.user().profile.admin
    
    0 讨论(0)
提交回复
热议问题