Account Creation w/ Alanning Roles


I’m trying achieve the following:

  • Disable account creation by users using the {{> loginButtons}}
  • Create a form where an Admin (role) can create users DONE
  • Send an e-mail notification with username & password DONE
  • Create a select with two roles (user & admin) DONE
  • Use value from created select while creating an account to add a role to the account I’m creating

I have created the following form:

My submit button code (main.js - client)

"submit .add-account": function(event, template){


var useremail =;
var userpwd =;
var userpwd2 =;
var userfirst =;
var userlast =;
var userusername =;
var role =;
var payment =;
 var letters = /^[a-zA-Z]+$/;

if(userpwd != userpwd2){
	Bert.alert('Passwords do not match!', 'danger' );
	return false;

if(empty(useremail) || empty(userpwd) || empty(userpwd2) || empty(userfirst) || empty(userlast) || empty(userusername) || empty(role)){
	Bert.alert('You cannot submit empty values, sadly', 'danger' );
return false;

	Bert.alert('Perhaps you want to pay your workers. No?', 'danger' );
	return false;

	Bert.alert('Your first name cannot be like that, I am sorry.', 'danger' );
	return false;

	Bert.alert('The last name is incorrect. Try a different one!', 'danger' );
	return false;

	Bert.alert('Weird symbols found in the username field. Hmmm..', 'danger' );
	return false;

if(userpwd.length < 4){
	Bert.alert('Your password is way too short! We are very secure, FYI.', 'danger' );
	return false;

  if (!Roles.userIsInRole(this.userId, ['admin'])) {
	Bert.alert('You are not an admin to do this.', 'danger' );
	return false;

console.log(useremail, userpwd, userfirst, userlast, userusername, role, payment);

  var account;
account = Accounts.createUser({
			email: useremail,
			password: userpwd,
			profile: {
				name_first:  userfirst,
				name_last:  userlast,
				username:  userusername,
				payment: payment,

			username:  userusername, 

//'sendEmail', useremail, "projectName account creation.", 
 //   "Your account ["+userusername+"] has been created. Password: ["+userpwd+"] Role: ["+role+"]. Login with your username/email & password here: URL");

Roles.addUsersToRoles(account, ['admin'], 'default-group'); = ''; = ''; = ''; = ''; = ''; = ''; = ''; = '';
Bert.alert('Worker added. Woop!', 'success' );



client.js - server

Meteor.publish(null, function (){
  return Meteor.roles.find({})

// Give authorized users access to sensitive data by group
Meteor.publish('secrets', function (group) {
    if (Roles.userIsInRole(this.userId, ['admin', 'default-group'], group)) {
        return Meteor.secrets.find({group: group});
    } else {
        // user not authorized. do not publish secrets

Error I’m getting:

alanning_roles.js?hash=74a6254…:643 Uncaught Error: Missing 'users' param
    at Object._updateUserRoles (alanning_roles.js?hash=74a6254…:643)
    at Object.addUsersToRoles (alanning_roles.js?hash=74a6254…:180)
    at Object.submit .add-account (main.js:344)
    at blaze.js?hash=f33d3df…:3775
    at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3df…:3744)
    at Blaze.View.<anonymous> (blaze.js?hash=f33d3df…:3774)
    at blaze.js?hash=f33d3df…:2617
    at Object.Blaze._withCurrentView (blaze.js?hash=f33d3df…:2271)
    at Blaze._DOMRange.<anonymous> (blaze.js?hash=f33d3df…:2616)
    at HTMLFormElement.<anonymous> (blaze.js?hash=f33d3df…:863)

If I try to do this in the console.

Roles.addUsersToRoles(Meteor.userId(), 'admin', 'default-group');

I get this error:

update failed: Access denied

Help please!

not entirely sure if this helps, but I am using

Accounts.onCreateUser((options, user) => {
    Roles.setRolesOnUserObj(user, ['admin']);

on the server and it works perfectly fine

1 Like

How do you use it? Where is it called? What function?
What are you passing for the options & user param? I think the issue might be that I’m trying to call this function on the client side instead of the server side.

you cannot setrole to user before it is created. you need to call method and in callback set role like this:

submit function [...]
Meteor.users.after.insert(function(userId, doc){
  Roles.addUsersToRoles(doc._id, ['user', 'default-group'], group);

or oncreateuser as keevandance said although i had some problems with that call ¯_(ツ)_/¯
and access denied error comes because you denied updating your user collection:

  update: () => false

So you need to either deny insert/update function and use methods or call function directly but allow updates.