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 CometChat object created during the initialization phase, call the login method below:

Method Signature:

Login(String username, String password, ICallbacks callback);

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

    cometChat.Login("user1","password123",new ICallbacks(success => successObject(success), fail => failObject(fail)));
    public void failObject(JSONObject p0)
    {
       //block of code
    }

    public void successObj(JSONObject p0)
    {
    //block of code
    }

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 CometChat object created during the initialization, and call the login method below Method Signature:

    Login(String userId, ICallbacks 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:

cometChat.login("10", new ICallbacks(success => successObject(success), fail => failObject(fail)));
    public void failObject(JSONObject p0)
    {
       //block of code
    }

    public void successObj(JSONObject p0)
    {
    //block of code
    }

Logout

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

    logout(ICallbacks callback)

ICallback Interface: The callback interface contains the methods successCallback and failCallback. The method successCallback triggers with successful logout and contains “logout successful” message in the JSON object. The method failCallback triggers with the unsuccessful logout and contains error information in a JSON object. Usage:

    cometchat.logout(new ICallbacks(success => successObject(success), fail => failObject(fail)));
    public void failObject(JSONObject p0)
    {
       //block of code
    }

    public void successObj(JSONObject p0)
    {
    //block of code
    }

  • Was this helpful?
  • Yes   No