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
UsegetLoggedInUser() to find out whether — and which — user has a persisted session, for example at app launch to decide whether to show your login screen. It returns a CallUser object if a user is logged in, or null if no session exists.
You never need it as a guard before login(): calling login() is always safe — if the same user is already logged in it returns the existing session without a network round trip, and if a different user is logged in the SDK switches to the new user automatically (see Switching Users).
- Kotlin
- Java
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
Switching Users
On a shared or reused device, calllogin() with the new user’s credentials — there is no need to check or clear the previous session yourself. If a different user is logged in, the SDK logs them out automatically before logging the new user in. Calling login() for the user who is already logged in simply returns the existing session.
- 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; the SDK stays initialized, so the next user can login() directly.
- Kotlin
- Java