Quick Reference for AI Agents & Developers
- Create user:
CometChat.createUser(user:apiKey:onSuccess:onError:)— passUser(uid:name:) - Update user:
CometChat.updateUser(user:apiKey:onSuccess:onError:) - Update logged-in user:
CometChat.updateCurrentUserDetails(user:onSuccess:onError:) - User properties:
uid,name,avatar,link,role,metadata,tags - Note: User creation requires API key (server-side recommended for production)
- Related: Retrieve Users · Users Overview · Authentication
- You add the user details in your database
- You create a user in CometChat
- You log in the user to your app
- You log in the user to CometChat (programmatically)
Creating a user
Ideally, user creation should take place at your backend. You can refer our Rest API to learn more about Creating a user and use the appropriate code sample based on your backend language. However, if you wish to create users on the fly, you can use thecreateUser() method. This method takes a User object and the Auth Key as input parameters and returns the created User object if the request is successful.
- Swift
Sample Payload
Sample Payload
Updating a user
Updating a user similar to creating a user should ideally be achieved at your backend using the Restful APIs. For more information, you can check the update a user section. However, this can be achieved on the fly as well using theupdateUser() method. This method takes a User object and the Auth Key as inputs and returns the updated User object on successful execution of the request.
- Swift
User object provided to the updateUser() method has the UID of the user to be updated set.
Sample Payload
Sample Payload
Updating logged-in user
Updating a logged-in user is similar to updating a user. The only difference being this method does not require an AuthKey. This method takes aUser object as input and returns the updated User object on the successful execution of the request.
- Swift
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.
Sample Payload
Sample Payload