> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Block & Unblock User

> Block or unblock another user with the social.plus SDKs.

Use the block API when the current user wants to block another user. Use the unblock API to remove that block.

The SDK updates relationship data after block and unblock calls. TypeScript returns the updated blocked payload (`follows` and `followCounts`). iOS, Android, and Flutter expose these actions as async or completable operations.

<Warning>
  Blocking affects relationship state, but downstream visibility and interaction behavior can vary by feature area and backend configuration. Keep feed, comment, search, and profile screens resilient by handling errors from those feature APIs and refreshing relationship status after block or unblock actions.
</Warning>

## Parameters

| Operation    | Parameter                 | Required | Description                                       |
| ------------ | ------------------------- | -------- | ------------------------------------------------- |
| Block user   | `userId` / `targetUserId` | Yes      | ID of the user the current user wants to block.   |
| Unblock user | `userId` / `targetUserId` | Yes      | ID of the user the current user wants to unblock. |

## Block User

Block a user when the current user wants to prevent or limit relationship-based interactions with that account.

<CodeGroup>
  ```swift iOS theme={null}
  let relationship = AmityUserRelationship()
  try await relationship.blockUser(userId: "target-user-id")
  ```

  ```kotlin Android theme={null}
  val disposable = AmityCoreClient.newUserRepository()
      .relationship()
      .blockUser(userId = targetUserId)
      .subscribe(
          {
              showSuccessMessage()
          },
          { error ->
              handleGeneralError(error)
          },
      )
  ```

  ```typescript TypeScript theme={null}
  import { UserRepository } from '@amityco/ts-sdk';

  const result = await UserRepository.Relationship.blockUser(userId);

  const followStatus = result.follows[0]?.status;
  const followCount = result.followCounts[0];
  ```

  ```dart Flutter theme={null}
  await AmityCoreClient.newUserRepository()
      .relationship()
      .blockUser(targetUserId);
  ```
</CodeGroup>

### Handle the blocked-user limit

A network caps how many users one account can block. When the current user is already at that cap, the block call fails with a "maximum blocked users reached" error instead of succeeding. On TypeScript this surfaces as the server error code `Amity.ServerError.MAX_BLOCKED_USERS_REACHED` (`400324`). Catch it and prompt the user to unblock someone before blocking another account.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { UserRepository } from '@amityco/ts-sdk';

  try {
    await UserRepository.Relationship.blockUser(userId);
  } catch (error) {
    if (error?.code === Amity.ServerError.MAX_BLOCKED_USERS_REACHED) {
      showBlockedUserLimitReached();
      return;
    }
    handleError(error);
  }
  ```

  ```swift iOS theme={null}
  let relationship = AmityUserRelationship()
  do {
      try await relationship.blockUser(userId: "target-user-id")
      showSuccessMessage()
  } catch {
      if error.isAmityErrorCode(.maxBlockedUsersReached) {
          // Already at the per-network block cap — prompt the user to unblock someone first.
          showBlockedUserLimitReached()
      } else {
          handleError(error)
      }
  }
  ```

  ```kotlin Android theme={null}
  AmityCoreClient.newUserRepository()
      .relationship()
      .blockUser(userId = targetUserId)
      .doOnComplete {
          showSuccessMessage()
      }
      .doOnError { error ->
          if (AmityError.from(error) == AmityError.MAX_BLOCKED_USERS_REACHED) {
              // Already at the per-network block cap — prompt the user to unblock someone first.
              showBlockedUserLimitReached()
          } else {
              handleGeneralError(error)
          }
      }
      .subscribe()
  ```
</CodeGroup>

## Unblock User

Unblock a user when the current user removes a previously created block.

<CodeGroup>
  ```swift iOS theme={null}
  let relationship = AmityUserRelationship()
  try await relationship.unblockUser(userId: "target-user-id")
  ```

  ```kotlin Android theme={null}
  val disposable = AmityCoreClient.newUserRepository()
      .relationship()
      .unblockUser(userId = targetUserId)
      .subscribe(
          {
              showSuccessMessage()
          },
          { error ->
              handleGeneralError(error)
          },
      )
  ```

  ```typescript TypeScript theme={null}
  import { UserRepository } from '@amityco/ts-sdk';

  const result = await UserRepository.Relationship.unBlockUser(userId);

  const followStatus = result.follows[0]?.status;
  const followCount = result.followCounts[0];
  ```

  ```dart Flutter theme={null}
  await AmityCoreClient.newUserRepository()
      .relationship()
      .unblockUser(targetUserId);
  ```
</CodeGroup>

## After Block Or Unblock

After a successful block or unblock action:

* Refresh follow info if the current screen shows relationship status or counters.
* Refresh follower/following lists if the current screen displays social graph data.
* Refresh blocked-user lists if the current screen lets users manage blocked accounts.
* Handle errors from other feature APIs instead of assuming all product surfaces update in the same way.

## Related Topics

<CardGroup cols={3}>
  <Card title="Manage Blocked Users" href="./manage-blocked-users" icon="list">
    Query the blocked-user list.
  </Card>

  <Card title="Users Who Blocked You" href="./manage-blocking-users" icon="user-slash">
    Query the reverse direction.
  </Card>

  <Card title="Follow/Unfollow User" href="../following/follow-unfollow-user" icon="user-plus">
    Change follow relationships.
  </Card>
</CardGroup>
