---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation-user
title: Moderate misbehaving users as a chat user
updated_at: 2026-06-04T11:09:05.899Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Moderate misbehaving users as a chat user

Regular chat users (without `secretKey`) can mute undesirable users to hide their messages. For admin moderation, see [Moderation as admin](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation).

**Mute list behavior:**

* Soft limit: 200 users
* Default: session-only persistence
* Optional: persist across sessions (32 KiB server limit applies)

:::warning Mute list limit
Persisted lists exceeding 32 KiB (~200 users) trigger HTTP 413 errors. Users remain muted for the session but won't persist.
:::

**Affected methods:**

* [channel.connect()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/watch)
* [channel.join()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/join)
* [channel.getHistory()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/history)
* [chat.listenForEvents()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/custom-events#receive-current-events)
* [chat.getEventsHistory()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/custom-events#get-historical-events)

:::note
Enable [App Context](https://youtu.be/9UEoSlngpYI) in the [Admin Portal](https://admin.pubnub.com/) to mute users.
:::

## Mute users as a regular chat user

Mute a specific user on all channels.

### Method signature

```ts
chat.mutedUsersManager.muteUser(userId): Promise<any>;
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| userId | string | Yes |  | [User ID](https://www.pubnub.com/docs/general/setup/users-and-devices) of the user you want to mute. |

#### Output

This method returns a `Promise` that succeeds when the data has been synced with the server. If [syncMutedUsers](https://www.pubnub.com/docs/chat/chat-sdk/build/configuration#sync-muted-users) is not enabled, the `Promise` always succeeds.

#### Errors

If the size of the mute list exceeds 32 KiB (roughly 200 users), you'll get the `HTTP 413 (Request Entity Too Large)` error.

### Sample code

```ts
import { Chat } from "@pubnub/chat"

const chat = Chat.init({
    publishKey: "demo",
    subscribeKey: "demo",
    userId: "myUniqueUserId"
})

let userToMute = "user_1905"

await chat.mutedUsersManager.muteUser(userToMute)
```

## Unmute users as a regular chat user

Remove a user from the mute list to see their messages and events again.

### Method signature

```ts
chat.mutedUsersManager.unmuteUser(userId): Promise<any>;
```

#### Input

| Parameter | Description |
| --- | --- |
| `userId` *Type: `string` | [User ID](https://www.pubnub.com/docs/general/setup/users-and-devices) of the user you want to unmute. |

#### Output

This method returns a `Promise` that succeeds when the data has been synced with the server. If [syncMutedUsers](https://www.pubnub.com/docs/chat/chat-sdk/build/configuration#sync-muted-users) is not enabled, the `Promise` always succeeds.

### Sample code

```ts
import { Chat } from "@pubnub/chat"

const chat = Chat.init({
    publishKey: "demo",
    subscribeKey: "demo",
    userId: "myUniqueUserId"
})

let userToUnmute = "user_1905"

await chat.mutedUsersManager.unmuteUser(userToUnmute)
```

## Check muted users

Inspect the mute list to see which users are muted.

### Method signature

```ts
chat.mutedUsersManager.mutedUsers
```

#### Output

This property returns a `Array<String>` where each `String` is a user ID of a muted user.

### Sample code

```ts
import { Chat } from "@pubnub/chat";

const chat = Chat.init({
  publishKey: "demo",
  subscribeKey: "demo",
  userId: "myUniqueUserId"
});

let userToMute = "user_1905";

// Mute the user
await chat.mutedUsersManager.muteUser(userToMute)

// Once the user is muted, get the list of muted users
const mutedUsers = chat.mutedUsersManager.mutedUsers;

console.log(mutedUsers)
```

## Persist the mute list

Set `syncMutedUsers: true` during [client initialization](https://www.pubnub.com/docs/chat/chat-sdk/build/configuration#initialize-pubnub) to persist the mute list across sessions.

:::warning Access Manager permissions
With Access Manager and `syncMutedUsers` enabled, grant these permissions (replace `$currentUserId` with the actual user ID):
* `read` on `PN_PRV.$currentUserId.mute1` channel
* `update`, `delete`, `get` on `PN_PRV.$currentUserId.mute1` user
:::

## Check restrictions

Check admin-imposed `mute` or `ban` restrictions:

* [Single user on one channel](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#one-user-on-one-channel)
* [Single user on all channels](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#one-user-on-all-channels)
* [All users on one channel](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#all-users-on-one-channel)

#### Sample code

##### Single user on a single channel

```ts
// List all mute and ban restrictions set by the admin
// for the user support_agent_15.

// reference "support-agent-15"
const user = await chat.getUser("support_agent_15")

// list all restrictions set for that user 
await user.getChannelsRestrictions()
```

##### All users on a single channel

```ts
// List all mute and ban restrictions set by the admin
// for the support channel.

// reference the "support" channel
const channel = await chat.getChannel("support")

// list all restrictions on the "support" channel
await channel.getUsersRestrictions()
```

##### Single user on all channels

```ts
// List all mute and ban restrictions set by the admin
// for the user support_agent_15.

// reference "support-agent-15"
const user = await chat.getUser("support_agent_15")

// list all restrictions set for that user 
await user.getChannelsRestrictions()
```

## Secure moderation

Client-side restrictions can be bypassed without [server-side logic](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#server-side-restrictions) using Access Manager. Combine with [client-side UI feedback](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#client-side-restrictions) to inform users of restrictions.

### Client-side restrictions

With [server-side permissions](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#server-side-restrictions) enforced via Access Manager, [read moderation restrictions](https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/moderation#check-restrictions) on the frontend to show users their status (e.g., popup messages, disabled input fields).

To react to permission changes in real-time:

1. Listen for moderation events. Set up a listener to listen for the moderation event type ("banned," "muted," or "lifted") generated when UI restrictions are added or removed. 1useEffect(() => {2 // Set up a listener for moderation events on the current user's channel3 const moderationListener = chat.listenForEvents({4 channel: chat.currentUser.id,5 type: "moderation",6 callback: handleModerationEvent,7 });8 9 return () => {10 moderationListener(); // Remove the moderation event listener on cleanup11 };12}, [chat]);
2. Act on moderation events. Update permissions in response to moderation events and generate new tokens if necessary. 1// Callback function to handle different moderation events2async function handleModerationEvent(moderationPayload: Event<"moderation">) {3 const { channelId, restriction, reason } = moderationPayload.payload;4 5 // Handle different moderation events6 if (restriction === "banned") {7 // Revoke specific permissions for banning8 console.log(`User ${chat.currentUser.id} is banned on channel ${channelId}. Reason: ${reason || "N/A"}`);9 10 // Revoke access rights specific to banning logic here11 // For example, you might remove write access12 13 } else if (restriction === "muted") {14 // Revoke specific permissions for muting15 console.log(`User ${chat.currentUser.id} is muted on channel ${channelId}. Reason: ${reason || "N/A"}`);16 17 // Revoke access rights specific to muting logic here18 // For example, you might remove read and write access19 } else if (restriction === "lifted") {20 // Grant access rights back21 console.log(`User ${chat.currentUser.id} restrictions lifted on channel ${channelId}`);22 23 // Granting access rights logic here24 }25 26 // Call the backend method to issue a new token after any moderation event27 const updatedToken = await getAuthToken(chat.currentUser.id);28 // Use the updated token as needed29}
3. Remove the event listener. 1return () => {2 moderationListener(); // Remove the moderation event listener on cleanup3};