Client callback on Accounts.CreateUser?

I have a form that is used to add users, it that calls a method with Accounts.CreateUser. I added a callback on the server but I’m getting an irritating error:

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

I need to somehow let the user know if an account has been successfully added, how can I go about doing this

You can do this:

if (Meteor.isServer) {
      const userId = Accounts.createUser({ email, password });
      if (userId) {
         // do something
      }
}

Only problem is I can’t return any success message to the client

You can make a method, for example

Meteor.methods({
  'users.register': ({ email, password }) => {
    const userId = Accounts.createUser({ email, password });
    return userId;
  },
});

then from client side, call this method to create account. In callback function, you can display the result.

2 Likes

Ok i think I got it now, Thank you so much!

You should also note that on the server, these methods throw errors, so use try/catch and throw new Meteor.Error to return errors to the client.

2 Likes