> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# User Management

> Create, update, and manage CometChat users programmatically using the React Native SDK. Includes user creation, profile updates, and the User class reference.

<Accordion title="AI Integration Quick Reference">
  ```javascript theme={null}
  // Create a user
  const user = new CometChat.User("user1");
  user.setName("Kevin");
  await CometChat.createUser(user, "AUTH_KEY");

  // Update a user
  user.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](https://api-explorer.cometchat.com).
</Accordion>

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`](/sdk/reference/entities#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](/sdk/react-native/authentication-overview)

<Note>
  User deletion is only available via the [REST API](https://api-explorer.cometchat.com/reference/delete-user) — there is no client-side SDK method for it.
</Note>

## Creating a User

User creation should ideally happen on your backend via the [REST API](https://api-explorer.cometchat.com/reference/creates-user).

<Warning>
  **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.
</Warning>

For client-side creation (development only), use `createUser()`:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    let authKey: string = "AUTH_KEY";
    let uid: string = "user1";
    let name: string = "Kevin";

    let user: CometChat.User = new CometChat.User(uid);

    user.setName(name);

    CometChat.createUser(user, authKey).then(
      (user: CometChat.User) => {
        console.log("user created", user);
      }, (error: CometChat.CometChatException) => {
        console.log("error", error);
      }
    );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    let authKey = "AUTH_KEY";
    let uid = "user1";
    let name = "Kevin";

    let user = new CometChat.User(uid);

    user.setName(name);

    CometChat.createUser(user, authKey).then(
      user => {
        console.log("user created", user);
      }, error => {
        console.log("error", error);
      }
    )
    ```
  </Tab>
</Tabs>

Returns a [`User`](/sdk/reference/entities#user) object. See [User Class](#user-class) for all available fields.

<Warning>
  UID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.
</Warning>

## Updating a User

Like creation, user updates should ideally happen on your backend via the [REST API](https://api-explorer.cometchat.com/reference/update-user).

For client-side updates (development only), use `updateUser()`:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    let authKey: string = "AUTH_KEY";
    let uid: string = "user1";
    let name: string = "Kevin Fernandez";

    let user: CometChat.User = new CometChat.User(uid);

    user.setName(name);

    CometChat.updateUser(user, authKey).then(
      (user: CometChat.User) => {
        console.log("user updated", user);
      }, (error: CometChat.CometChatException) => {
        console.log("error", error);
      }
    )
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    let authKey = "AUTH_KEY";
    let uid = "user1";
    let name = "Kevin Fernandez";

    let user = new CometChat.User(uid);

    user.setName(name);

    CometChat.updateUser(user, authKey).then(
      user => {
        console.log("user updated", user);
      }, error => {
        console.log("error", error);
      }
    )
    ```
  </Tab>
</Tabs>

Ensure the [`User`](/sdk/reference/entities#user) object has the correct `UID` set.

Returns a [`User`](/sdk/reference/entities#user) object. See [User Class](#user-class) for all available fields.

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

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    let uid: string = "user1";
    let name: string = "Kevin Fernandez";

    let user: CometChat.User = new CometChat.User(uid);

    user.setName(name);

    CometChat.updateCurrentUserDetails(user).then(
      (user: CometChat.User) => {
        console.log("user updated", user);
      }, (error: CometChat.CometChatException) => {
        console.log("error", error);
      }
    );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    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);
      }
    )
    ```
  </Tab>
</Tabs>

The method returns a [`User`](/sdk/reference/entities#user) object.

## Deleting a user

User deletion is only available via the [REST API](https://api-explorer.cometchat.com/reference/delete-user).

## User Class

| Field         | Editable                                            | Information                                                          |
| ------------- | --------------------------------------------------- | -------------------------------------------------------------------- |
| uid           | specified on user creation. Not editable after that | Unique identifier of the user                                        |
| name          | Yes                                                 | Display name of the user                                             |
| avatar        | Yes                                                 | URL to profile picture of the user                                   |
| link          | Yes                                                 | URL to profile page                                                  |
| role          | Yes                                                 | User role of the user for role based access control                  |
| metadata      | Yes                                                 | Additional information about the user as JSON                        |
| status        | No                                                  | Status of the user. Could be either online/offline                   |
| statusMessage | Yes                                                 | Any custom status message that needs to be set for a user            |
| lastActiveAt  | No                                                  | The unix timestamp of the time the user was last active.             |
| hasBlockedMe  | No                                                  | A boolean that determines if the user has blocked the logged in user |
| blockedByMe   | No                                                  | A boolean that determines if the logged in user has blocked the user |
| tags          | Yes                                                 | A list of tags to identify specific users                            |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Retrieve Users" icon="users" href="/sdk/react-native/retrieve-users">
    Fetch and filter user lists with pagination.
  </Card>

  <Card title="User Presence" icon="circle-dot" href="/sdk/react-native/user-presence">
    Monitor real-time online/offline status.
  </Card>

  <Card title="Block Users" icon="ban" href="/sdk/react-native/block-users">
    Block and unblock users.
  </Card>

  <Card title="Authentication" icon="key" href="/sdk/react-native/authentication-overview">
    Log users into CometChat.
  </Card>
</CardGroup>
