Create, update, and manage CometChat users programmatically using the JavaScript SDK. Includes user creation, profile updates, and the User class reference.
AI Integration Quick Reference
// Create a userconst user = new CometChat.User("user1");user.setName("Kevin");await CometChat.createUser(user, "AUTH_KEY");// Update a useruser.setName("Kevin Fernandez");await CometChat.updateUser(user, "AUTH_KEY");// Update logged-in user (no auth key needed)await CometChat.updateCurrentUserDetails(user);
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:
User registers in your app → Create user in CometChat
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 uid = "user1";let name = "Kevin Fernandez";let user = new CometChat.User(uid);user.setName(name);CometChat.updateCurrentUserDetails(user).then( user => { console.log("user updated", user); }, error => { console.log("error", error); })