Authentication

Login

This section provides you with the required information regarding the user authentication mechanism.

The below-mentioned methods need to be used to log in the user. Please follow the steps below to log in the user into CometChat.

Product:
Using the CCCometChat object created during the initialization phase, call the login method below:

Method Signature:

 login(String username, String password,success-callback,failure-callback);

The parameters needed for the login method are as follows:
userName – Username of the user.
password – Password for the user.
success-callback – This is an instance of the Callback interface which contains the success method.This helps you to know if the login attempt was successful. Usage:
failure-callback – This is an instance of the Callback interface which contains the failure methods.This helps you to know if any failure occurs during Login.
Usage:

 CCCometChat.login("user1,"password123",successCallback(response) {},failCallback(response) {});

The initialization steps remain the same for the cloud variant. The login mechanism uses just the userId of the user instead of the username and password. Use the CCCometChat object created during the initialization, and call the login method below Method Signature:

 login(String userId, Callbacks callback); 

Parameters
userId – User ID of the user.
callback – This is an instance of the Callback interface which contains the success and failure methods.This helps you to know if the login attempt was successful. Usage:

 CCCometChat.login("10", function success(data){  },function error(data){  });

Logout

Calling this function will end the current session and clears user data. Method Signature:

 logout(success-callback,failure-callback);

Callback Interface: The callback interface contains the methods success-callback and fail-callback. The method successCallback triggers with successful logout and contains “logout successful” message. The method failCallback triggers with unsuccessful logout and contains error information.
Usage:

 CCCometchat.logout(function success(data){  },function error(data){  });

  • Was this helpful?
  • Yes   No