How to make the user autologin after calling Accounts.createUser from a method

Is it possible to make the user automatically log in after calling the Accounts.createUser from a method? I just learnt that the Accounts.createUser only returns the userId on the server side.

‘users.register’(username, password) {

  let _userId;

  check(username, String);
  check(password, String);

  _userId = Accounts.createUser({
    email: username,
    password: password
  });

  Roles.addUsersToRoles(_userId, 'normal-user');

}
1 Like

It will work only when you use Accounts.createUser on the client. If you use it on the server side you can create callback on the client side and use Meteor.loginWithPassword(email, password); This is what I do in my sId package here .

4 Likes

Thanks so much @juliancwirko. It worked.