Skip to main content
Quick Reference - Register a login listener:
The CometChat SDK provides you with real-time updates for the login and logout events. This can be achieved using the LoginListener class. LoginListener provides the following 4 methods:

Add Login Listener

To add the LoginListener, use the addLoginListener() method provided by the SDK. It takes a unique identifier for the listener and an instance of the LoginListener class.

Remove Login Listener

To stop receiving events related to login and logout, use the removeLoginListener() method and pass the ID of the listener that needs to be removed.
Listener Cleanup: Always remove your login listeners when they are no longer needed (e.g., when a component unmounts) to prevent memory leaks and unexpected behavior. Use removeLoginListener() with the same listener ID you used when adding it.
  • Use unique, descriptive listener IDs to avoid conflicts (e.g., "login-screen-listener")
  • Add listeners in component mount lifecycle and remove them on unmount
  • Handle all four events to provide a complete user experience
  • Use loginFailure to display user-friendly error messages
  • Listener not firing: Ensure the listener was added before the login/logout event occurs
  • Duplicate events: Check that you’re not adding the same listener multiple times without removing it first
  • Memory leaks: Verify that removeLoginListener() is called when the component unmounts

Next Steps

Authentication Overview

Learn about login methods and session management

User Presence

Track real-time online/offline status of users

Connection Listener

Monitor and manage WebSocket connection status

Send Messages

Start sending text, media, and custom messages