Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Create a user
User user = User(uid: "user1", name: "Kevin");
CometChat.createUser(user, "AUTH_KEY", onSuccess: (User user) {
  debugPrint("User created: ${user.name}");
}, onError: (CometChatException e) {
  debugPrint("Error: ${e.message}");
});

// Update a user (requires API Key)
User updatedUser = User(uid: "user1", name: "Kevin Fernandez");
CometChat.updateUser(updatedUser, "AUTH_KEY", onSuccess: (User user) {
  debugPrint("User updated: ${user.name}");
}, onError: (CometChatException e) {
  debugPrint("Error: ${e.message}");
});

// Update logged-in user (no auth key needed)
User currentUser = User(name: "New Name");
CometChat.updateCurrentUserDetails(currentUser, onSuccess: (User user) {
  debugPrint("User updated: ${user.name}");
}, onError: (CometChatException e) {
  debugPrint("Error: ${e.message}");
});
Note: User creation/deletion should ideally happen on your backend via the REST API.
Users must exist in CometChat before they can log in. This page covers creating, updating, and deleting users. All methods that return user data return a User object. The typical flow:
  1. User registers in your app → Create user in CometChat
  2. User logs into your app → Log user into CometChat
User deletion is only available via the REST API — there is no client-side SDK method for it.

Creating a User

User creation should ideally happen on your backend via the REST API.
Security: Never expose your Auth Key in client-side production code. User creation and updates using Auth Key should ideally happen on your backend server. Use client-side creation only for prototyping or development.
For client-side creation (development only), use createUser():
String authKey = "AUTH_KEY"; // Replace with the auth key of app
User user = User(uid: "usr1", name: "Kevin"); // Replace with name and uid of user

CometChat.createUser(user, authKey, onSuccess: (User user) {
  debugPrint("Create User successful $user");
}, onError: (CometChatException e) {
  debugPrint("Create User Failed with exception ${e.message}");
});

Parameters

ParameterTypeDescription
userUserA User object containing the details of the user to be created. The uid and name fields are required.
authKeyStringYour CometChat Auth Key. Use only for development — never expose in production client code.
onSuccessFunction(User user)Callback triggered on successful user creation, returning the created User object.
onErrorFunction(CometChatException excep)Callback triggered on failure, returning a CometChatException with error details.
Returns a User object. See User Class for all available fields.
On Success — A User object containing all details of the created user:User Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the user"usr1"
namestringDisplay name of the user"Kevin"
linkstringProfile linknull
avatarstringAvatar URLnull
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayList of tags associated with the user[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity0
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_UID_NOT_FOUND"
messagestringHuman-readable error message"The specified UID does not exist."
detailsstringAdditional technical details"Please provide a valid UID for the user."
UID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.

Updating a User

Like creation, user updates should ideally happen on your backend via the REST API. For client-side updates (development only), use updateUser():
String apiKey = "AUTH_KEY"; // Replace with the auth key of app
User user = User(uid: "usr1", name: "Kevin Fernandez");

CometChat.updateUser(user, apiKey, onSuccess: (User user) {
  debugPrint("User updated: $user");
}, onError: (CometChatException e) {
  debugPrint("Update User Failed with exception ${e.message}");
});
Ensure the User object has the correct UID set.

Parameters

ParameterTypeDescription
userUserA User object with the uid of the user to update and the fields to change.
apiKeyStringYour CometChat Auth Key. Use only for development — never expose in production client code.
onSuccessFunction(User retUser)Callback triggered on successful update, returning the updated User object.
onErrorFunction(CometChatException excep)Callback triggered on failure, returning a CometChatException with error details.
Returns a User object. See User Class for all available fields.
On Success — A User object containing all details of the updated user:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the user"usr1"
namestringDisplay name of the user"Kevin Fernandez"
linkstringProfile linknull
avatarstringAvatar URLnull
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayList of tags associated with the user[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity0
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_UID_NOT_FOUND"
messagestringHuman-readable error message"The specified UID does not exist."
detailsstringAdditional technical details"Please provide a valid UID for the user."

Updating Logged-in User

Use updateCurrentUserDetails() to update the current user without an Auth Key. Note: You cannot update the user’s role with this method.
User user = User(name: 'Updated Name');

CometChat.updateCurrentUserDetails(user, onSuccess: (User updatedUser) {
  debugPrint("Updated User: $updatedUser");
}, onError: (CometChatException e) {
  debugPrint("Updated User exception : ${e.message}");
});

Parameters

ParameterTypeDescription
userUserA User object with the fields to update. The uid is ignored — only the logged-in user is updated.
onSuccessFunction(User retUser)Callback triggered on successful update, returning the updated User object.
onErrorFunction(CometChatException excep)Callback triggered on failure, returning a CometChatException with error details.
The method returns a User object.
On Success — A User object containing all details of the updated user:User Object:
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the user"cometchat-uid-1"
namestringDisplay name of the user"Updated Name"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
metadataobjectCustom metadata{}
statusstringOnline status"online"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayList of tags associated with the user[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_UID_NOT_FOUND"
messagestringHuman-readable error message"The specified UID does not exist."
detailsstringAdditional technical details"Please provide a valid UID for the user."
By using the updateCurrentUserDetails() method one can only update the logged-in user irrespective of the UID passed. Also, it is not possible to update the role of a logged-in user.

Deleting a User

User deletion is only available via the REST API.

User Class

FieldEditableInformation
uidspecified on user creation. Not editable after thatUnique identifier of the user
nameYesDisplay name of the user
avatarYesURL to profile picture of the user
linkYesURL to profile page
roleYesUser role of the user for role based access control
metadataYesAdditional information about the user as JSON
statusNoStatus of the user. Could be either online/offline
statusMessageYesAny custom status message that needs to be set for a user
lastActiveAtNoThe unix timestamp of the time the user was last active.
hasBlockedMeNoA boolean that determines if the user has blocked the logged in user
blockedByMeNoA boolean that determines if the logged in user has blocked the user
tagsYesA list of tags to identify specific users

Next Steps

Retrieve Users

Fetch and filter user lists with pagination.

User Presence

Monitor real-time online/offline status.

Block Users

Block and unblock users.

Authentication

Log users into CometChat.