Meteor not setting username with Accounts.createUser [solved]


#1

Hello,

I am using Accounts.createUser on the server side and it is not adding the username when creating, nor is it adding it from creating an account from facebook or google.

Client side I have

Template.signup.events({
  'submit form': function(event) {
    event.preventDefault();
    var userName = event.target.userName.value;
    var emailVar = event.target.signupEmail.value;
    var passwordVar = event.target.signupPassword.value;
    Meteor.call('newUser', userName, emailVar, passwordVar, ()=>{
      Meteor.loginWithPassword(emailVar, passwordVar);
    });
  }
});

Server side I have:

Meteor.startup(() => {
  // code to run on server at startup
  
/* REMOVED OTHER FUNCTIONS */
  
  Accounts.onCreateUser(function (options, user) {

      if (user.services.google) {
        user.username = user.services.google.name;
        user.emails = [{address: user.services.google.email}];
      }
      else if(user.services.facebook) {
        user.username = user.services.facebook.name;
        user.emails = [{address: user.services.facebook.email}];
      }

      return user;
  });

});

Meteor.methods({
  newUser(name,email,password){
    Accounts.createUser({
      username: name,
      email: email,
      password: password
    });
  }
})

I am using login with google, and login with facebook which is creating the account fine but it also not creating the username as it should with onCreateUser.

Also as a side note, what is the easiest way to get all user data, and also remove all users and start fresh.

Thank you,
Mike Acre


#2

I figured out my issue was with my schema I had set up. It did not include a username, I simply forgot I had already set up a user Schema.