Quick Reference for AI Agents & Developers
LoginListener provides real-time updates for authentication events, enabling you to respond to login/logout across devices and sessions.
Use Cases
- Sync UI state across browser tabs
- Handle session expiration gracefully
- Track authentication analytics
- Implement single-session enforcement
Listener Events
| Event | Description | Data |
|---|---|---|
loginSuccess | User logged in successfully | CometChat.User |
loginFailure | Login attempt failed | CometChat.CometChatException |
logoutSuccess | User logged out successfully | None |
logoutFailure | Logout attempt failed | CometChat.CometChatException |
Implementation
- JavaScript
- TypeScript
Remove Listener
Remove the listener when it’s no longer needed:- JavaScript
- TypeScript
React Integration
- JavaScript
- TypeScript
Multi-Tab Synchronization
Keep authentication state synchronized across browser tabs:- JavaScript
- TypeScript
Best Practices
Use Unique Listener IDs
Use Unique Listener IDs
Ensure each listener has a unique ID to prevent conflicts.
Clean Up on Unmount
Clean Up on Unmount
Always remove listeners when components unmount.
Handle All Events
Handle All Events
Implement handlers for both success and failure cases.