Account.createUser callback not working in meteorjs

I am developing an application with a js meteorite. I created one meteor method for creating a user. This shows me the following error: -

Accounts.createUser with a callback that is not yet supported on the server.

here is my meteor method

How can I add a callback to account.createUser?

  Meteor.startup(function () {
     Meteor.methods({
      postForm:function(doc){

     var result = Accounts.createUser({
    username: doc.username,
    password: doc.password,
    email: doc.emails,
    profile: {
      lastname: doc.lastname,
      contact:doc.phoneNumber,
      bdat:doc.bod,
      address:doc.address
    }
  },function(){
    console.log('hello');
   });
  }
   });


});
+4
source share
2 answers

The “else” in this error message is probably the author’s error. According to the documentation :

On server [ Accounts.createUser], returns the newly created user ID.

, Accounts.createUser : , , . , " " , createUser. , user_id, Meteor.users.find(). , .

, , Accounts.createUser() , . , , - " " , , . ( , )

+7

, "". : Exception while invoking method Error: Accounts.createUser with callback not supported on the server yet.

, , , . .

. , . , - , ​​ , , . .

Meteor.methods({
    postForm:function(doc){
        try {
          var result = Accounts.createUser({
              username: doc.username,
              password: doc.password,
              email: doc.emails,
              profile: {
                  lastname: doc.lastname,
                  contact:doc.phoneNumber,
                  bdat:doc.bod,
                  address:doc.address
              }
          });
          if(result){
              // are you using roles?
              // Roles.addUsersToRoles(result, doc.roles);  
              return result;
          }
        }
        catch(err){
            return err;
        }
    }
});

, "" callback not supported. , . Accounts.validateNewUser((user), , .

, ... .

Meteor.call('postForm', newUser, function(error, response) {
    if (error) {
        console.log('postForm: Error: ', error);
    }
    if (response) {
        console.log('postForm: Response: ', response);
    }
});

. , , , - ""!

+5

All Articles