Search code examples
meteormeteor-accounts

How do I update currentUser after Accounts.createUser() and Accounts.loginWithPassword()?


I am trying to create my own UI for signing up/logging in users:

'submit .signin': function(event){
    var user = {'email':event.target.email.value, 'password' :event.target.password.value}
    Accounts.createUser(user, function(err) {
         if (err){
            console.log(err);
         } else
            console.log('success!');
    });
    Meteor.loginWithPassword(user['email'], user['password'], function(error){
            if(error){
                console.log(error)
            }
            else{
                console.log('success')
            }
    });
}

My question is once this code logs in the user, how do I set the currentUser the way loginButtons automatically does after you sign in. Thanks!


Solution

  • You don't have to call login after user is created. To modify user data you can use http://docs.meteor.com/#/full/accounts_oncreateuser

    See examples here: https://github.com/juliancwirko/meteor-s-id