Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

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

// Create a user
let user = User(uid: "user1", name: "Kevin")
CometChat.createUser(user: user, apiKey: "AUTH_KEY",
    onSuccess: { user in }, onError: { error in })

// Update a user
let updateUser = User(uid: "user1", name: "Kevin Fernandez")
CometChat.updateUser(user: updateUser, apiKey: "AUTH_KEY",
    onSuccess: { user in }, onError: { error in })

// Update logged-in user (no auth key needed)
CometChat.updateCurrentUserDetails(user: currentUser,
    onSuccess: { user in }, onError: { error in })
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. 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():
let newUser : User = User(uid: "user1", name: "Kevin") // Replace with your uid and the name for the user to be created.
let authKey = "AUTH_KEY" // Replace with your Auth Key.
CometChat.createUser(user: newUser, apiKey: authKey, onSuccess: { (User) in
      print("User created successfully. \(User.stringValue())")
  }) { (error) in
     print("The error is \(String(describing: error?.description))")
}
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():
let updateUser : User = User(uid: "user1", name: "Kevin Fernandez") // Replace with your uid and the name for the user to be created.
let authKey = "AUTH_KEY" // Replace with your Auth Key.
CometChat.updateUser(user: newUser1, apiKey: authKey, onSuccess: { (User) in
     print("User updated successfully. \(User.stringValue())")
 }) { (error) in
     print("The error is \(String(describing: error?.description))")
 }
Ensure the User object has the correct UID set.

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.
let currentUser = User(uid: "cometchat-uid-1", name: "Andrew Joseph")
CometChat.updateCurrentUserDetails(user: currentUser, onSuccess: { user in
	print("Updated user object",user)
}, onError: { error in
	print("Update user failed with error: \(error?.errorDescription)")
})
The method updates the logged-in user irrespective of the UID passed.

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 Dictionary
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.