Why User Sync?
CometChat needs to know about your users to:- Route calls — Connect callers to the right recipients
- Identify participants — Display names and avatars in calls
- Track history — Associate call logs with specific users
- Manage permissions — Control who can call whom
Creating Users
Choose the method that best fits your workflow:Dashboard
Add users manually via the CometChat Dashboard. Ideal for quick testing or small teams.
SDK
Create users programmatically via SDK methods. Perfect for auto-provisioning during sign-up.
REST API
Create users using the REST API. Best for batch imports or backend workflows.
User Requirements
Required Fields
| Field | Type | Description |
|---|---|---|
uid | String | Unique user identifier. Alphanumeric, max 100 characters. Must be unique across your app. |
Optional Fields
| Field | Type | Description |
|---|---|---|
name | String | Display name shown in calls and participant lists |
avatar | String | URL to profile image |
metadata | Object | Custom JSON data for your application |
role | String | User role (default, admin, etc.) |
tags | Array | Tags for categorization and filtering |
Example User Object
Authentication Flow
1
Create User (One-time)
Create the user in CometChat when they sign up for your app. This only needs to happen once per user.Server-side (recommended):
2
Generate Auth Token
Generate an authentication token for the user on your server. This token is used to log in the user on the client.Server-side:Response:
3
Login User (Client-side)
Use the auth token to log in the user via the SDK. This establishes a session for making calls.JavaScript:
4
Ready for Calls
Once logged in, the user can initiate and receive calls. The SDK handles all session management automatically.
Authentication Methods
Auth Token (Recommended for Production)
Generate tokens server-side using the REST API. This is the secure method for production apps. Pros:- Secure — API key never exposed to clients
- Controlled — You decide when tokens are issued
- Auditable — Token generation can be logged
- User logs into your app
- Your server generates a CometChat auth token
- Token is sent to the client
- Client uses token to log into CometChat
Auth Key (Development Only)
Use the Auth Key directly in client code for quick testing. Never use in production. JavaScript:Sync Strategies
Just-in-Time Provisioning
Create CometChat users when they first need calling functionality:Batch Import
Import existing users via REST API when integrating CometChat:Webhook Sync
Use webhooks to keep CometChat users in sync with your database:- User signs up → Create CometChat user
- User updates profile → Update CometChat user
- User deletes account → Delete CometChat user
User Lifecycle
Creating Users
Users can be created via:- REST API (server-side)
- SDK
createUsermethod - Dashboard (manual)
Updating Users
Update user details when they change in your app:Deleting Users
Remove users when they leave your platform:Soft Delete: By default, deleted users are soft-deleted and can be restored. Use
permanent=true query parameter for permanent deletion.Best Practices
Do
- Generate auth tokens server-side
- Use consistent UIDs across your app
- Keep user data in sync
- Handle token expiration gracefully
Don’t
- Expose API keys in client code
- Use Auth Key in production
- Create duplicate users
- Store auth tokens long-term