Skip to main content
Version: v4

Login Listeners

The CometChat SDK provides you with real-time updates for the login and logout events. This can be achieved using the LoginListener class provided. LoginListener consists of 4 events that can be triggered. These are as follows:

Callback MethodInformation
loginSuccess(User user)Informs you that the login was successful and provides you with a user object containing the data for the user that logged in
loginFailure(CometChatException e)Informs you about the failure while logging in the user and provides you with the reason for the failure wrapped in an object of the CometChatException class
logoutSuccess()Informs you about the user being logged out successfully.
logoutFailure(CometChatException e)Informs you about the failure while logging out the user. The reason for the failure can be obtained from the object of the CometChatException class provided.

To add the LoginListener, you need to use the addLoginListener() method provided by the SDK which takes a unique identifier for the listener and object of the LoginListener class itself.

We suggest adding the listener in the init method of the Stateful class or at the initialization of class where you wish to receive these events in.

class Class_Name with LoginListener {

// String loginListenerId = "UNIQUE_LISTENER_ID";
// CometChat.addLoginListener(loginListenerId, Class_Name()); // add this in init

void loginSuccess(User user) {
debugPrint("LoginListener loginSuccess $user");
}


void logoutFailure(CometChatException e) {
debugPrint("logoutFailure ${e.message}");
}


void logoutSuccess() {
debugPrint("LoginListener logout Success");
}


void loginFailure(CometChatException e) {
debugPrint("LoginListener loginFailure ${e.message}");
}
}

In order to stop receiving events related to login and logout you need to use the removeLoginListener() method provided by the SDK and pas the ID of the listener that needs to be removed.

CometChat.removeLoginListener("UNIQUE_LISTENER_ID");