> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 Method      | Information                                                                                                                                                      |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| loginSuccess(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(event)  | 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(event) | 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.          |

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

<Tabs>
  <Tab title="Add Login Listener">
    ```javascript theme={null}
    let listenerID = "UNIQUE_LISTENER_ID";
    CometChat.addLoginListener(
      listenerID,
      new CometChat.LoginListener({
          loginSuccess: (e) => {
              console.log("LoginListener :: loginSuccess", e);
          },
          loginFailure: (e) => {
              console.log("LoginListener :: loginFailure", e);
          },
          logoutSuccess: () => {
              console.log("LoginListener :: logoutSuccess");
          },
          logoutFailure: (e) => {
              console.log("LoginListener :: logoutFailure", e);
          }
      })
    );  
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    var listenerID: string = "UNIQUE_LISTENER_ID";
    CometChat.addLoginListener(
      listenerID,
      new CometChat.LoginListener({
          loginSuccess: (user: CometChat.User) => {
              console.log("LoginListener :: loginSuccess", user);
          },
          loginFailure: (error: CometChat.CometChatException) => {
              console.log("LoginListener :: loginFailure", error);
          },
          logoutSuccess: () => {
              console.log("LoginListener :: logoutSuccess");
          },
          logoutFailure: (error: CometChat.CometChatException) => {
              console.log("LoginListener :: logoutFailure", error);
          }
      })
    );
    ```
  </Tab>
</Tabs>

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

<Tabs>
  <Tab title="Remove Login Listener">
    ```javascript theme={null}
    let listenerID = "UNIQUE_LISTENER_ID";
    CometChat.removeLoginListener(listenerID); 
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    var listenerID: string = "UNIQUE_LISTENER_ID";
    CometChat.removeLoginListener(listenerID);
    ```
  </Tab>
</Tabs>
