如何向Meteor.users()添加新字段?

问题描述 投票:0回答:1

我有一个按钮,可以将新用户插入Meteor.users()

在服务器中我有这个方法:

Meteor.methods({
    'addUser': function(user) {
        return Accounts.createUser(user)
    }
})

并在客户端(点击后按钮):

var newUser = {
            email: t.find('#email').value,
            password: t.find('#pwd').value,
            profile: { name: t.find('#name').value, group: t.find('#userType').value },
            roles: checkedRoles // I can successfully console.log(checkedRoles) which is an array of strings.
        }

        Meteor.call('addUser', newUser, function(error){
            if(error){
                sweetAlert(error)
            } else {
                sweetAlert('User Successfully Added')
            }
        })

使用上面的代码,添加了用户但没有roles字段。

我的问题是,如何将roles字段添加到新添加的用户?

meteor meteor-accounts
1个回答
3
投票

使用alanning:roles包:

meteor add alanning:roles

然后(在你的服务器端方法):

const userId = Accounts.createUser(user);

Roles.addUsersToRoles(userId, user.roles);

© www.soinside.com 2019 - 2024. All rights reserved.