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

# Retrieve Users

> Fetch user lists, search users, get logged-in user details, and retrieve online user counts using the CometChat React Native SDK.

<Info>
  **Quick Reference** - Fetch users:

  ```javascript theme={null}
  // Get logged-in user
  const me = await CometChat.getLoggedinUser();

  // Fetch user list
  const usersRequest = new CometChat.UsersRequestBuilder().setLimit(30).build();
  const users = await usersRequest.fetchNext();

  // Get specific user
  const user = await CometChat.getUser("UID");
  ```
</Info>

<Note>
  **Available via:** [SDK](/sdk/react-native/retrieve-users) | [REST API](/rest-api/users/list) | [UI Kits](/ui-kit/react-native/users)
</Note>

## Retrieve Logged In User Details

You can get the details of the logged-in user using the `getLoggedInUser()` method. This method can also be used to check if the user is logged in or not. If the method returns `Promise` with reject callback, it indicates that the user is not logged in and you need to log the user into CometChat SDK.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var user = CometChat.getLoggedinUser().then(
    user => {
      console.log("user details:", { user });
    }, error => {
      console.log("error getting details:", { error });
    }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    CometChat.getLoggedinUser().then(
      (user: CometChat.User) => {
          console.log("user details:", { user });
      }, (error: CometChat.CometChatException) => {
          console.log("error getting details:", { error });
      }
    ); 
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `getLoggedinUser()` returns a `User` object containing the logged-in user's details:

  <span id="logged-in-user-object" />

  **User Object:**

  | Parameter       | Type    | Description                                       | Sample Value                                                 |
  | --------------- | ------- | ------------------------------------------------- | ------------------------------------------------------------ |
  | `uid`           | string  | Unique identifier of the user                     | `"cometchat-uid-7"`                                          |
  | `name`          | string  | Display name of the user                          | `"Henry Marino"`                                             |
  | `avatar`        | string  | URL to user's avatar image                        | `"https://artriva.com/media/k2/galleries/20/d.jpg"`          |
  | `authToken`     | string  | Authentication token for the user                 | `"cometchat-uid-7_177199269018c2c2995f0b69b3844abc9fdb9843"` |
  | `status`        | string  | User's online status                              | `"online"`                                                   |
  | `role`          | string  | User's role                                       | `"default"`                                                  |
  | `lastActiveAt`  | number  | Unix timestamp of last activity                   | `1771853565`                                                 |
  | `hasBlockedMe`  | boolean | Whether this user has blocked the current user    | `false`                                                      |
  | `blockedByMe`   | boolean | Whether the current user has blocked this user    | `false`                                                      |
  | `deactivatedAt` | number  | Timestamp when user was deactivated (0 if active) | `0`                                                          |
  | `tags`          | array   | Tags associated with the user                     | `["vip"]`                                                    |
</Accordion>

This method will return a `User` object containing all the information related to the logged-in user.

## Retrieve List of Users

In order to fetch the list of users, you can use the `UsersRequest` class. To use this class i.e to create an object of the `UsersRequest` class, you need to use the `UsersRequestBuilder` class. The `UsersRequestBuilder` class allows you to set the parameters based on which the users are to be fetched.

The `UsersRequestBuilder` class allows you to set the below parameters:

### Set Limit

This method sets the limit i.e. the number of users that should be fetched in a single iteration.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .build();  
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with basic limit returns an array of `User` objects:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                             | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                 | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                          | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                                                                                                                    |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
</Accordion>

### Set Search Keyword

This method allows you to set the search string based on which the users are to be fetched.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let searchKeyword = "super";
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .setSearchKeyword(searchKeyword)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let searchKeyword: string = "super";
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .setSearchKeyword(searchKeyword)
      .build();
    ```
  </Tab>
</Tabs>

### Search In

This method allows you to define in which user property should the searchKeyword be searched. This method only works in combination with `setSearchKeyword()`. By default the keyword is searched in both UID & Name.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let searchKeyword = "super";
    let searchIn = ["uid", "name"];
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .setSearchKeyword(searchKeyword)
                      .searchIn(searchIn)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let searchKeyword: string = "super";
    let searchIn: Array<String> = ["uid", "name"];
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .setSearchKeyword(searchKeyword)
      .searchIn(searchIn)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with search filter returns an array of `User` objects matching the search criteria:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                     |
  | ---------------- | ------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"123456"`                                                                                                                       |
  | `name`           | string  | Display name of the user                             | `"Farhan Ahmed"`                                                                                                                 |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://st2.depositphotos.com/38197074/46684/v/450/depositphotos_466848082-stock-illustration-initial-letter-vector-logo.jpg"` |
  | `status`         | string  | User's online status                                 | `"offline"`                                                                                                                      |
  | `role`           | string  | User's role                                          | `"extrarole"`                                                                                                                    |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1768988601`                                                                                                                     |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                          |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `true`                                                                                                                           |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                              |
  | `metadata`       | object  | Custom metadata attached to the user                 | `{"metadata": "something"}`                                                                                                      |
  | `blockedByMeAt`  | number  | Timestamp when blocked by current user               | `1772164515`                                                                                                                     |
  | `blockedAt`      | number  | Timestamp of block action                            | `1772164515`                                                                                                                     |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"123456_user_cometchat-uid-7"`                                                                                                  |
</Accordion>

### Set Status

The status based on which the users are to be fetched. The status parameter can contain one of the below two values:

* CometChat.USER\_STATUS.ONLINE - will return the list of only online users.
* CometChat.USER\_STATUS.OFFLINE - will return the list of only offline users.

If this parameter is not set, will return all the available users.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .setStatus(CometChat.USER_STATUS.ONLINE)
                      .build()
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .setStatus(CometChat.USER_STATUS.ONLINE)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with status filter returns an array of `User` objects with matching status:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                             | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                 | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                          | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                                                                                                                    |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
</Accordion>

### Hide Blocked Users

This method is used to determine if the blocked users should be returned as a part of the user list. If set to true, the user list will not contain the users blocked by the logged in user.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .hideBlockedUsers(true)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .hideBlockedUsers(true)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with `hideBlockedUsers(true)` returns an array of `User` objects excluding blocked users:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                             | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                 | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                          | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                                                                                                                    |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
</Accordion>

### Set Roles

This method allows you to fetch the users based on multiple roles.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let roles = ["default", "dev"];
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .setRoles(roles)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let roles: Array<String> = ["default", "dev"];
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .setRoles(roles)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with roles filter returns an array of `User` objects with matching roles:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                             | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                 | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                          | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                                                                                                                    |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
</Accordion>

### Friends Only

This property when set to true will return only the friends of the logged-in user.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .friendsOnly(true)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .friendsOnly(true)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with `friendsOnly(true)` returns an array of `User` objects who are friends:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                             | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                 | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                          | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                                                                                                                    |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
</Accordion>

### Set Tags

This method accepts a list of tags based on which the list of users is to be fetched. The list fetched will only contain the users that have been tagged with the specified tags.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let tags = ["tag1", "tag2"];
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .setTags(tags)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let tags: Array<String> = ["tag1", "tag2"];
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .setTags(tags)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with tags filter returns an array of `User` objects with matching tags:

  | Parameter        | Type    | Description                                          | Sample Value                     |
  | ---------------- | ------- | ---------------------------------------------------- | -------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"user509"`                      |
  | `name`           | string  | Display name of the user                             | `"again stokes"`                 |
  | `status`         | string  | User's online status                                 | `"offline"`                      |
  | `role`           | string  | User's role                                          | `"default"`                      |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1759921301`                     |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                          |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                          |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                              |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-7_user_user509"` |
</Accordion>

### With Tags

This property when set to true will fetch tags data along with the list of users.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .withTags(true)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .withTags(true)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with `withTags(true)` returns an array of `User` objects including the `tags` field:

  | Parameter        | Type    | Description                                          | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                             | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                 | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                          | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                                                                                                                                                                    |
  | `tags`           | array   | Tags associated with the user                        | `["vip"]`                                                                                                                                                                                                              |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
</Accordion>

### Set UIDs

This method accepts a list of UIDs based on which the list of users is fetched. A maximum of `25` users can be fetched.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let UIDs = ["cometchat-uid-1", "cometchat-uid-2"];
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .setUIDs(UIDs)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let UIDs: Array<String> = ["cometchat-uid-1", "cometchat-uid-2"];
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .setUIDs(UIDs)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with UIDs filter returns an array of `User` objects for the specified UIDs:

  | Parameter        | Type    | Description                                          | Sample Value                                                            |
  | ---------------- | ------- | ---------------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-5"`                                                     |
  | `name`           | string  | Display name of the user                             | `"John Paul"`                                                           |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-5.webp"` |
  | `status`         | string  | User's online status                                 | `"offline"`                                                             |
  | `role`           | string  | User's role                                          | `"admin"`                                                               |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772087140`                                                            |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                 |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                 |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                     |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-5_user_cometchat-uid-7"`                                |
</Accordion>

### Sort By

This method allows you to sort the User List by a specific property of User. By default the User List is sorted by `status => name => UID` . If `name` is pass to the `sortBy()` method the user list will be sorted by `name => UID`.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let UIDs = ["cometchat-uid-1", "cometchat-uid-2"];
    let sortBy = "name";
    let usersRequest = new CometChat.UsersRequestBuilder()
                      .setLimit(limit)
                      .sortBy(sortBy)
                      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let sortBy: string = "name";
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .sortBy(sortBy)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with `sortBy("name")` returns an array of `User` objects sorted by name:

  | Parameter        | Type    | Description                                          | Sample Value               |
  | ---------------- | ------- | ---------------------------------------------------- | -------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"1"`                      |
  | `name`           | string  | Display name of the user                             | `"1"`                      |
  | `status`         | string  | User's online status                                 | `"offline"`                |
  | `role`           | string  | User's role                                          | `"default"`                |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1770017972`               |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                    |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                    |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                        |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"1_user_cometchat-uid-7"` |
</Accordion>

### Sort By Order

This method allows you to sort the User List in a specific order. By default the user list is sorted in ascending order.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let sortByOrder = "desc";
    let usersReques = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .sortByOrder(sortOrder)
      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let sortOrder: string = "desc";
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .sortOrder(sortOrder)
      .build();
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` with `sortByOrder("desc")` returns an array of `User` objects in descending order:

  | Parameter        | Type    | Description                                          | Sample Value                   |
  | ---------------- | ------- | ---------------------------------------------------- | ------------------------------ |
  | `uid`            | string  | Unique identifier of the user                        | `"voip3"`                      |
  | `name`           | string  | Display name of the user                             | `"voip3"`                      |
  | `status`         | string  | User's online status                                 | `"offline"`                    |
  | `role`           | string  | User's role                                          | `"default"`                    |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1770193733`                   |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                        |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                        |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                            |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-7_user_voip3"` |
</Accordion>

Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the UsersRequest class.

Once you have the object of the UsersRequest class, you need to call the fetchNext() method. Calling this method will return a list of User objects containing n number of users where n is the limit set in the builder class.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var limit = 30;
    var usersRequest = new CometChat.UsersRequestBuilder()
      										.setLimit(limit)
      										.build();

    usersRequest.fetchNext().then(
    userList => {
      console.log("User list received:", userList);
    }, error => {
      console.log("User list fetching failed with error:", error);
    }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let usersRequest: CometChat.UsersRequest = new CometChat.UsersRequestBuilder()
      .setLimit(limit)
      .build();

    usersRequest.fetchNext().then(
      (userList: CometChat.User[]) => {
          console.log("User list received:", userList);
      }, (error: CometChat.CometChatException) => {
          console.log("User list fetching failed with error:", error);
      }
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` returns an array of `User` objects:

  <span id="fetch-next-user-object" />

  **User Object (per item in array):**

  | Parameter        | Type    | Description                                           | Sample Value                                                                                                                                                                                                           |
  | ---------------- | ------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                         | `"cometchat-uid-6"`                                                                                                                                                                                                    |
  | `name`           | string  | Display name of the user                              | `"Ronald Jerry"`                                                                                                                                                                                                       |
  | `avatar`         | string  | URL to user's avatar image                            | `"https://media.istockphoto.com/id/1682296067/photo/happy-studio-portrait-or-professional-man-real-estate-agent-or-asian-businessman-smile-for.jpg?s=612x612&w=0&k=20&c=9zbG2-9fl741fbTWw5fNgcEEe4ll-JegrGlQQ6m54rg="` |
  | `status`         | string  | User's online status                                  | `"online"`                                                                                                                                                                                                             |
  | `role`           | string  | User's role                                           | `"default"`                                                                                                                                                                                                            |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                       | `1772163872`                                                                                                                                                                                                           |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user        | `false`                                                                                                                                                                                                                |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user        | `false`                                                                                                                                                                                                                |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)     | `0`                                                                                                                                                                                                                    |
  | `conversationId` | string  | Conversation ID between this user and logged-in user  | `"cometchat-uid-6_user_cometchat-uid-7"`                                                                                                                                                                               |
  | `tags`           | array   | Tags associated with the user (when `withTags(true)`) | `["vip"]`                                                                                                                                                                                                              |
  | `metadata`       | object  | Custom metadata attached to the user (if set)         | `{"metadata": "something"}`                                                                                                                                                                                            |
  | `blockedByMeAt`  | number  | Timestamp when blocked by current user (if blocked)   | `1772164515`                                                                                                                                                                                                           |
  | `blockedAt`      | number  | Timestamp of block action (if blocked)                | `1772164515`                                                                                                                                                                                                           |
</Accordion>

## Retrieve Particular User Details

To get the information of a user, you can use the `getUser()` method.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let UID = "UID";
    CometChat.getUser(UID).then(
    user => {
      console.log("User details fetched for user:", user);
    }, error => {
      console.log("User details fetching failed with error:", error);
    }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let UID: string = "UID";
    CometChat.getUser(UID).then(
      (user: CometChat.User) => {
          console.log("User details fetched for user:", user);
      }, (error: CometChat.CometChatException) => {
          console.log("User details fetching failed with error:", error);
      }
    );
    ```
  </Tab>
</Tabs>

The `getUser()` method takes the following parameters:

| Parameter | Description                                                |
| --------- | ---------------------------------------------------------- |
| UID       | The UID of the user for whom the details are to be fetched |

<Accordion title="Response">
  **On Success** — `getUser()` returns a `User` object containing the requested user's details:

  <span id="get-user-object" />

  **User Object:**

  | Parameter        | Type    | Description                                          | Sample Value                                                            |
  | ---------------- | ------- | ---------------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`            | string  | Unique identifier of the user                        | `"cometchat-uid-5"`                                                     |
  | `name`           | string  | Display name of the user                             | `"John Paul"`                                                           |
  | `avatar`         | string  | URL to user's avatar image                           | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-5.webp"` |
  | `status`         | string  | User's online status                                 | `"offline"`                                                             |
  | `role`           | string  | User's role                                          | `"admin"`                                                               |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                      | `1772087140`                                                            |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user       | `false`                                                                 |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user       | `false`                                                                 |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)    | `0`                                                                     |
  | `tags`           | array   | Tags associated with the user                        | `["tag1"]`                                                              |
  | `conversationId` | string  | Conversation ID between this user and logged-in user | `"cometchat-uid-5_user_cometchat-uid-7"`                                |
</Accordion>

## Get online user count

To get the total count of online users for your app, you can use the `getOnlineUserCount()` method.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    CometChat.getOnlineUserCount().then(
    userCount => {
      console.log("Total online user count:", userCount);
    }, error => {
      console.log("Online user count fetching failed with error:", error);
    }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    CometChat.getOnlineUserCount().then(
      (userCount: number) => {
          console.log("Total online user count:", userCount);
      }, (error: CometChat.CometChatException) => {
          console.log("Online user count fetching failed with error:", error);
      }
    ); 
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `getOnlineUserCount()` returns an object with the count:

  <span id="online-user-count-object" />

  **Response Object:**

  | Parameter | Type   | Description                  | Sample Value |
  | --------- | ------ | ---------------------------- | ------------ |
  | `count`   | number | Total number of online users | `2`          |
</Accordion>

This method returns the total online user count for your app.

## Best Practices

<AccordionGroup>
  <Accordion title="Use pagination for large user lists">
    Always use `fetchNext()` with a reasonable `setLimit()` value (e.g., 20-30) rather than fetching all users at once. This improves performance and reduces memory usage.
  </Accordion>

  <Accordion title="Reuse the same UsersRequest instance for pagination">
    The `UsersRequest` object maintains an internal cursor. Creating a new instance resets the cursor, causing the same page to be fetched repeatedly. Reuse the same instance across `fetchNext()` calls.
  </Accordion>

  <Accordion title="Filter server-side, not client-side">
    Use the builder's filter methods (`setSearchKeyword`, `setStatus`, `setRoles`, `setTags`) to narrow results at the API level rather than fetching all users and filtering in your app.
  </Accordion>
</AccordionGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="fetchNext returns empty list">
    Verify the logged-in user session is active. Also check if filters like `setRoles`, `setTags`, or `setStatus` are too restrictive. Try removing filters to confirm users exist.
  </Accordion>

  <Accordion title="getUser returns error">
    Ensure the UID exists in your CometChat app. UIDs are case-sensitive — double-check the exact UID string.
  </Accordion>

  <Accordion title="Blocked users still appearing in list">
    By default, blocked users are included in the user list. Use `hideBlockedUsers(true)` in the `UsersRequestBuilder` to exclude them.
  </Accordion>
</AccordionGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="User Management" icon="user-plus" href="/sdk/react-native/user-management">
    Create, update, and delete users in CometChat
  </Card>

  <Card title="Block Users" icon="ban" href="/sdk/react-native/block-users">
    Block and unblock users, retrieve blocked user lists
  </Card>

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

  <Card title="Retrieve Conversations" icon="comments" href="/sdk/react-native/retrieve-conversations">
    Fetch conversation lists with last message and unread counts
  </Card>
</CardGroup>
