---
url: https://talkjs.com/docs/Guides/Web_Components/Remove_Users/
title: "Remove users from a group chat | Web Components"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# Remove users from a group chat

Remove a participant using the Data API or your backend.

You can remove a participant from a group chat with the JavaScript Data API in your Web Components app. You can also remove participants from your backend with the REST API.

Removing a participant removes their membership of that conversation. It doesn't delete their user account, their messages, or the conversation for other participants.

For the method reference, see [`ParticipantRef.delete()`](https://talkjs.com/docs/Data_APIs/JavaScript/Participants/#ParticipantRef__delete).

To add someone instead, see [Add users to a group chat](https://talkjs.com/docs/Guides/Web_Components/Add_Users/).

## Remove a participant

You can remove a participant from your frontend or backend.

### Frontend

This example assumes you've completed the relevant [Web Components getting-started guide](https://talkjs.com/docs/UI_Components/JavaScript/), and have an existing conversation with participants.

Get a reference to the participant and call `delete()`:

```js
import { getTalkSession } from '@talkjs/core';

const session = getTalkSession({
  appId: '<APP_ID>',
  userId: '<CURRENT_USER_ID>',
});

try {
  const conversation = session.conversation('<CONVERSATION_ID>');
  await conversation.participant('<USER_ID_TO_REMOVE>').delete();
  console.log('Participant removed');
} catch (error) {
  console.error('Could not remove participant:', error);
}
```

Replace the placeholders with your app ID, the current user's ID, the conversation ID, and the ID of the participant to remove. If authentication is enabled, [authenticate the session](https://talkjs.com/docs/Features/Security/Authentication/) before making the request.

The promise resolves when removal completes. Deleting a participant who has already been removed is also treated as success.

#### Browser synchronization

Removing participants through the Data API requires [conversation synchronization from the browser](https://talkjs.com/docs/Features/Security/Browser_Synchronization/#conversation-synchronization). If it's disabled, calling `delete()` will reject the promise.

If your application needs to restrict who can remove participants, the operation needs to be performed on your backend by interacting with the [TalkJS REST API](https://talkjs.com/docs/REST_API/). Check the signed-in user's permission to remove the target participant before calling TalkJS. Hiding a remove button in the frontend doesn't enforce that permission.

### Backend

Use the [leave conversation REST API endpoint](https://talkjs.com/docs/REST_API/Participation/#leave-conversation):

```sh
curl 'https://api.talkjs.com/v1/<APP_ID>/conversations/<CONVERSATION_ID>/participants/<USER_ID_TO_REMOVE>' \
  -H 'Authorization: Bearer <SECRET_KEY>' \
  -X DELETE
```

This request should be run on your backend so that the secret key can be kept out of browser code.

## Let the current user leave

To let the current user leave a conversation, remove their own participation:

```js
await session
  .conversation(conversationId)
  .participant(session.currentUser)
  .delete();
```

Call this function from your application's leave button and handle failures before showing a success state. The browser synchronization requirement also applies when removing yourself.

## What happens in the UI?

Components subscribe to conversation data, so you don't need to remount the inbox or manually delete a conversation-list item after removal. The conversation no longer appears in the removed user's conversation list. If their chatbox is still pointed at that conversation, it can no longer display it as a participant. Your app can navigate them elsewhere or clear its selected conversation after a successful leave action.

Other participants keep access to the conversation and its existing messages, including messages sent by the removed user.

Removal isn't a permanent ban. If the user is added again, they regain access to the conversation history, including messages sent before they rejoined. If users can create or update participation through browser synchronization, removal alone doesn't prevent them from rejoining. Enforce any restrictions in your backend and configure browser synchronization accordingly.

## Make a participant read-only instead

If the user should still be able to read the conversation, change their access rather than removing them:

```js
await session
  .conversation('<CONVERSATION_ID>')
  .participant('<USER_ID>')
  .edit({ access: 'Read' });
```

This keeps them as a participant but prevents them from sending messages. It requires browser conversation synchronization; you can also [modify participation from your backend](https://talkjs.com/docs/REST_API/Participation/#modify-participation).
