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

# Block Users

> Block and unblock users, and retrieve the list of blocked users using the CometChat React Native SDK.

<Accordion title="AI Integration Quick Reference">
  ```javascript theme={null}
  // Block users
  await CometChat.blockUsers(["UID1", "UID2"]);

  // Unblock users
  await CometChat.unblockUsers(["UID1", "UID2"]);

  // Get blocked users list
  let request = new CometChat.BlockedUsersRequestBuilder().setLimit(30).build();
  let blockedUsers = await request.fetchNext();
  ```

  **Directions:** `BLOCKED_BY_ME` | `HAS_BLOCKED_ME` | `BOTH` (default)
</Accordion>

Blocking a user prevents all communication between them and the logged-in user — messages, calls, and presence updates are all suppressed. You can block and unblock users by UID, and fetch the blocked users list with filtering and pagination.

## Block Users

Block users to prevent all communication with them. Use `blockUsers()` with an array of UIDs.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    const usersList: String[] = ["UID1", "UID2", "UID3"];

    CometChat.blockUsers(usersList).then(
      (list: Object) => {
          console.log("users list blocked", { list });
      }, (error: CometChat.CometChatException) => {
          console.log("Blocking user fails with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const usersList = ["UID1", "UID2", "UID3"];

    CometChat.blockUsers(usersList).then(
    list => {
      console.log("users list blocked", { list });
    }, error => {
      console.log("Blocking user fails with error", error);
    }
    );
    ```

    Alternatively, you can use the `async/await` syntax:

    ```javascript theme={null}
    const usersList = ["UID1", "UID2", "UID3"];

    try {
      const list = await CometChat.blockUsers(usersList);
      console.log("users list blocked", { list });
    } catch (error) {
      console.log("Blocking user fails with error", error);
    }
    ```
  </Tab>
</Tabs>

Returns an object with UIDs as keys and `"success"` or `"fail"` as values. Each [`User`](/sdk/reference/entities#user) in the request is processed independently.

## Unblock Users

Unblock previously blocked users using `unblockUsers()` with an array of UIDs.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    const usersList: String[] = ["UID1", "UID2", "UID3"];

    CometChat.unblockUsers(usersList).then(
      (list: Object) => {
          console.log("users list unblocked", { list });
      }, (error: CometChat.CometChatException) => {
          console.log("Unblocking user fails with error", error);
      }
    ); 
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const usersList = ["UID1", "UID2", "UID3"];

    CometChat.unblockUsers(usersList).then(
    list => {
      console.log("users list unblocked", { list });
    }, error => {
      console.log("unblocking user fails with error", error);
    }
    );
    ```

    Alternatively, you can use the `async/await` syntax:

    ```javascript theme={null}
    const usersList = ["UID1", "UID2", "UID3"];

    try {
      const list = await CometChat.unblockUsers(usersList);
      console.log("users list unblocked", { list });
    } catch (error) {
      console.log("unblocking user fails with error", error);
    }
    ```
  </Tab>
</Tabs>

Returns an object with UIDs as keys and `"success"` or `"fail"` as values. Each [`User`](/sdk/reference/entities#user) in the request is processed independently.

## Get List of Blocked Users

Use `BlockedUsersRequestBuilder` to fetch blocked users with filtering and pagination.

### Set Limit

Sets the number of blocked users to fetch per request.

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

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

### Set Search Keyword

Filters blocked users by a search string.

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

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

### Set Direction

Filters by block direction:

* `BLOCKED_BY_ME` — Users blocked by the logged-in user
* `HAS_BLOCKED_ME` — Users who have blocked the logged-in user
* `BOTH` — Both directions (default)

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let blockedUsersRequest: CometChat.BlockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
      .setLimit(limit)
      .setDirection(CometChat.BlockedUsersRequest.directions.BLOCKED_BY_ME)
      .build();
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    let limit = 30;
    let blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
     .setLimit(limit)
     .setDirection(CometChat.BlockedUsersRequest.directions.BLOCKED_BY_ME)
     .build();
    ```
  </Tab>
</Tabs>

After configuring the builder, call `build()` to get the `BlockedUsersRequest` object, then call `fetchNext()` to retrieve blocked users.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30;
    let blockedUsersRequest: CometChat.BlockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
      .setLimit(limit)
      .build();

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

  <Tab title="JavaScript">
    ```javascript theme={null}
    const limit = 30;
    const blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
                      				.setLimit(limit)
                      				.build();
    blockedUsersRequest.fetchNext().then(
    userList => {
      console.log("Blocked user list received:", userList);
    }, error => {
      console.log("Blocked user list fetching failed with error:", error);
    }
    );
    ```
  </Tab>
</Tabs>

The `fetchNext()` method returns an array of [`User`](/sdk/reference/entities#user) objects representing blocked users.

Relevant fields to access on returned users:

| Field        | Getter              | Return Type | Description                                      |
| ------------ | ------------------- | ----------- | ------------------------------------------------ |
| blockedByMe  | `getBlockedByMe()`  | `boolean`   | Whether the logged-in user has blocked this user |
| hasBlockedMe | `getHasBlockedMe()` | `boolean`   | Whether this user has blocked the logged-in user |

***

## Next Steps

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

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

  <Card title="User Management" icon="users-gear" href="/sdk/react-native/user-management">
    Create, update, and delete users
  </Card>

  <Card title="Flag Message" icon="flag" href="/sdk/react-native/flag-message">
    Report inappropriate messages from users
  </Card>
</CardGroup>
