[SOLVED] Accounts.createUser() changes logged in user

I am using accounts-password. I can only create a new user when I am logged in as an admin (using alanning:roles). When i fill out the form and submit it, the newly created user becomes the user currently logged in. I just want to create the user and not have the user switch. How do I accomplish this?

The script that creates a new user is like this:

Template.users_new.events({  
  'submit form': function(event){
     event.preventDefault();
     var fullname = $('[name=create_user_fullname]').val();
     var email = $('[name=create_user_email]').val();
     var password = $('[name=create_user_password]').val();
     var role = $('[name=create_user_role]').val();
     var id;
     id = Accounts.createUser({
       username: "",
       email: email,
       password: password,
       profile: {
           fullname: fullname
       }
     }, function(error) {
       if(error) {
         // did not work
       } else {
         // user created
       }
     });
     Roles.addUsersToRoles(id, [role], 'default_group');
   }
});

Using Accounts.createUser() on the client, automatically logs in the user.

In your server-only files, create a Meteor Method that creates the user instead.

ex. Meteor.call(‘createUserAccount’, user);

The server side version of Accounts.createUser() does not automatically log in the account, and has a few other differences.

http://docs.meteor.com/#/full/accounts_createuser

1 Like

See what you can get out of this.

Worked. Will have to figure out a way to do the callback now.