AI Integration Quick Reference
AI Integration Quick Reference
Get from: CometChat Dashboard → Your App → API & Auth Keys
login() method.
Before You Log In
Create a User
A user must exist in CometChat before they can log in.- During development: Create users from the CometChat Dashboard. Five test users are already available with UIDs
cometchat-uid-1throughcometchat-uid-5. - In production: Call the Create User REST API when a user signs up in your app.
We have set up 5 users for testing with UIDs:
cometchat-uid-1, cometchat-uid-2, cometchat-uid-3, cometchat-uid-4, and cometchat-uid-5.Check for an Existing Session
The SDK persists the logged-in user’s session locally. Before callinglogin(), always check whether a session already exists — this avoids unnecessary login calls.
- Java
- Kotlin
getLoggedInUser() returns null, no active session exists and you need to call login().
Login using Auth Key
This straightforward authentication method is ideal for proof-of-concept (POC) development or during the early stages of application development. For production environments, however, we strongly recommend using an Auth Token instead of an Auth Key to ensure enhanced security.- Java
- Kotlin
After the user logs in, their information is returned in the
User object.
Login using Auth Token
This advanced authentication procedure does not use the Auth Key directly in your client code, ensuring better security.- Create a User via the CometChat API when the user signs up in your app.
- Create an Auth Token via the CometChat API for the new user every time the user logs in to your app.
- Pass the Auth Token to your client and use it in the
login()method.
- Java
- Kotlin
After the user logs in, their information is returned in the
User object.
Logout
You can use thelogout() method to log out the user from CometChat. We suggest you call this method once your user has been successfully logged out from your app.
- Java
- Kotlin
Login Listener
You can listen for login and logout events in real time usingLoginListener. This is useful for updating UI state or triggering side effects when the auth state changes.
Add a Listener
- Java
- Kotlin
Remove a Listener
- Java
- Kotlin
Next Steps
Send a Message
Start sending text, media, and custom messages to users and groups
User Management
Retrieve and manage users in your application
Connection Status
Monitor the SDK connection state in real time
Key Concepts
Understand core CometChat concepts and terminology