【问题标题】:How can I add new field to Meteor.users()?如何向 Meteor.users() 添加新字段?
【发布时间】:2017-12-30 00:39:56
【问题描述】:

我有一个按钮可以将新用户插入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】:

使用alanning:roles 包:

meteor add alanning:roles

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

const userId = Accounts.createUser(user);

Roles.addUsersToRoles(userId, user.roles);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 2017-04-21
    • 2023-03-06
    • 2014-08-30
    • 1970-01-01
    • 2021-07-10
    相关资源
    最近更新 更多