Logging in

Once users are registered with your application (after completing the user verification process if required) they will be able to log in with their username, phone number or email address.

Logging in with a password

Here is the sample code for authenticating a user. Invoke the authenticate method with a combination of a username (or a phone number or an email address) and a password.

  • var username = "user123456789";
    var password = "123ABC";
    
    // Authenticate a user.
    KiiUser.authenticate(username, password).then(
      function(theUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var theUser = error.target;
        var errorString = error.message;
      }
    );
  • var username = "user123456789";
    var password = "123ABC";
    
    // Authenticate a user.
    KiiUser.authenticate(username, password, {
      success: function(theUser) {
        // Do something.
      },
      failure: function(theUser, errorString) {
        // Handle the error.
      }
    })

Investigating failed logins

The string invalid_grant will be set in the errorString of the failure callback if the specified user does not exist or if the password is invalid. The same error message will be also set if the specified user is currently disabled by the app administrator. See Error details to learn more the exception handling.

For security reasons, the SDK cannot determine which is the cause of the exception. On the other hand, the app administrator can identify the error cause by checking the developer log.