Creating a New User by Specifying Parameters

The code executes the user sign-up with the username and password passed from the client side as the custom parameters (the actual scenario would be like "allowing a user to create a new account on behalf of his/her friend).

This server code is asynchronous.

function main(params, context, done) {
  // Create a user.
  var user = KiiUser.userWithUsername(params.username,
                                      params.password);

  // Register the user.
  user.register({
    success: function(user) {
      // Return the username.
      done(user.getUsername());
    },
    failure: function(user, errorString) {
      done(errorString);
    }
  });
}

Here is the brief explanation of what is taking place in the sample.

  • Executes KiiUser.userWithUsername() method and creates a new account. This requires the username and password. We get these values from the first argument as the execution parameters.
  • Returns the username of the newly-created account to the client. We use the callback function done() that is passed as the third argument.