sourceplaze
sourceplaze

Reputation: 333

How can I add new field to Meteor.users()?

I have a button that inserts new user to Meteor.users().

In the server I have this method:

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

And in the client (After button is clicked):

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')
            }
        })

Using the above code, the user is added but without the roles field.

My question is, how can I add the roles field to the newly added user?

Upvotes: 0

Views: 52

Answers (1)

Behrouz Riahi
Behrouz Riahi

Reputation: 1791

Use alanning:roles package:

meteor add alanning:roles

then (in your server side method):

const userId = Accounts.createUser(user);

Roles.addUsersToRoles(userId, user.roles);

Upvotes: 3

Related Questions