Skip to main content
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: 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.

React Example

If you’re using React, register the listener inside a useEffect hook and clean it up on unmount:
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.
Always remove login listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.

Next Steps

Authentication

Learn about login methods and auth tokens

Connection Status

Monitor the SDK connection state in real time

All Real-Time Listeners

Complete reference for all SDK event listeners

WebSocket Management

Manually manage WebSocket connections