Can't add user attribute using Accounts.onCreateUser

后端 未结 2 1633
北荒
北荒 2021-01-14 23:33

I tried to add an attribute \'permission\' to all newly created users. But it somehow doesn\'t work. I use this code to add the attribute

 Accounts.onCreateU         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-15 00:12

    You create it properly. The problem is that client does not see this value. Taken from documentation:

    By default the server publishes username, emails, and profile

    So you need to publish / subscribe for the additional fields.

    Server:

    Meteor.publish('userData', function() {
      if(!this.userId) return null;
      return Meteor.users.find(this.userId, {fields: {
        permission: 1,
      }});
    });
    

    Client:

    Deps.autorun(function(){
      Meteor.subscribe('userData');
    });
    

提交回复
热议问题