Skip to main content
Note: User creation/updates should ideally happen on your backend using REST API.
When a user registers in your app, create them in CometChat. When they log in, log them into CometChat as well.

Creating a user

Ideally, user creation should happen on your backend using the REST API. For on-the-fly creation during development, use the createUser() method with a User object and your API Key.
API Key Security: The API Key should only be used for development and testing. In production, create and update users on your backend server using the REST API to keep your API Key secure. Never expose API Keys in production client code.
UID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.

Updating a user

Use updateUser() with a User object and API Key. Ideally done on your backend via the REST API.
Please make sure the User object provided to the updateUser() method has the UID of the user to be updated.

Updating logged-in user

Use updateCurrentUserDetails() to update the currently logged-in user’s profile. No API Key required.
By using the updateCurrentUserDetails() method, you can only update the logged-in user regardless of the UID passed. Also, it is not possible to update the role of a logged-in user.

Deleting a user

Deleting a user can only be achieved via the RESTful APIs. For more information, see the delete a user section.

User Class

User Payload Structure

The User object returned by SDK methods contains the following fields:Sample User Object:

Next Steps

Authentication

Log users into CometChat after creating their accounts

Retrieve Users

Fetch user lists and search for specific users

User Presence

Track user online/offline status in real-time

Block Users

Implement user blocking and unblocking features