First, put addUser
method on server only (i.e. in server
dir):
Meteor.methods({
addUser: function (attrs) {
var user = Meteor.user();
if (!user) // you can also check this.userId here
throw new Meteor.Error(401, 'Please login.');
if (!attrs.profile.firstName)
throw new Meteor.Error(422, 'Please include a first name.');
if (!attrs.profile.lastName)
throw new Meteor.Error(422, 'Please include a first name.');
if (!attrs.email)
throw new Meteor.Error(422, 'Please include an email.');
var user = _.pick(attrs, ['firstName', 'lastName', 'email']);
var newUserId = Accounts.createUser(attrs);
Accounts.sendEnrollmentEmail(newUserId);
}
});
Then, on the client, you can do something like:
Meteor.call('addUser', attrs, function (err) {
if (err) {
console.log('something went wrong :(');
}
});