Sample UsersCometChat provides 5 test users:
cometchat-uid-1, cometchat-uid-2, cometchat-uid-3, cometchat-uid-4, and cometchat-uid-5.Check Login Status
Before callinglogin(), check if a user is already logged in using getLoggedInUser(). The SDK maintains the session internally, so you only need to login once per user session.
- Kotlin
- Java
getLoggedInUser() method returns a CallUser object if a user is logged in, or null if no session exists.
Login with UID and API Key
This method is suitable for development and testing. For production apps, use Auth Token login instead.- Kotlin
- Java
Login with Auth Token
This is the recommended authentication method for production applications. The Auth Token is generated server-side, keeping your API Key secure.Auth Token Flow
- User authenticates with your backend
- Your backend calls the CometChat Create Auth Token API
- Your backend returns the Auth Token to the client
- Client uses the Auth Token to login
- Kotlin
- Java
CallUser Object
On successful login, the callback returns aCallUser object containing user information:
Logout
Calllogout() when the user signs out of your application. This clears the local session and disconnects from CometChat services.
- Kotlin
- Java