Login/Logout

To add Login support in your application,

Include CustomUI.js in your index.html file to access the Custom UI functionality in your Cordova app

All the method calls will invoke their respective callback blocks as defined below.

1. Set CometChat URL



function callbackmeth(result){

   alert(result);

}

CustomUI.setapi(api,callbackmeth);

2. Login to CometChat
Login to CometChat on your website by any of the 3 available methods. Also make sure that your chatlogin() function in integration.php should be configured to handle any of the login mechanisms you opt for.

a) You can login to CometChat using the userID. All data related to the previous user will be cleared.



function callbackmeth(result){

   alert(result);

}

CustomUI.loginUserid("5",callbackmeth);

Response: Callback containing login success message
Eg:



success = {
      "message"="Login Successful";
} 

b) You can also login to CometChat using the username and password. All data related to the previous user will be cleared.



function callbackmeth(result){

   alert(result);

}

CustomUI.loginUsername("Tony Stark”","password",callbackmeth);

Response: Callback containing login success message
Eg:



success = {
      "message"="Login Successful";
} 

Once you have logged-in to CometChat you can use all other features and functionalities available in CometChat SDK.

3. Logout
Calling this function will end the current session and clears user data



function callbackmeth(result){

   alert(result);

}

CustomUI.logoutWithSuccess(callbackmeth);

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!