Can't add user attribute using Accounts.onCreateUser

后端 未结 2 1609
北荒
北荒 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:19

    Meteor.users.findOne(Meteor.userId) should be changed to Meteor.users.findOne(Meteor.userId()).

    Also, I'm not sure what fields on the user object that actually are transmitted to the client. You might need to changeuser.permission = 'default' to options.profile.permission = 'default' so your Accounts.onCreateUser will look like this:

    Accounts.onCreateUser(function(options, user) {
        if(!options.profile){
           options.profile = {}
        }
        options.profile.permission = 'default'
        if (options.profile)
            user.profile = options.profile;
        return user;
    });
    

提交回复
热议问题