---
title: Realtime Chat
description: Real-time chat component for collaborative applications
preview: |-
---
## Installation
### Set up the Supabase client
This block requires a Supabase client for Nuxt.js. If your project already has one, reuse it and update the block's imports to match your client. Otherwise, install the client:
Configure the environment variables described in the [Nuxt.js client guide](/library/docs/nuxtjs/client#getting-started) before using the block.
### Install the block
## Introduction
The Realtime Chat component provides a complete chat interface that enables users to exchange messages in real-time within a shared room.
## How it works under the hood
This chat component uses **Supabase Realtime Broadcast** to send and receive messages between connected clients.
Messages sent through Broadcast are:
- delivered in real time to other connected clients
- **not stored** unless you handle persistence yourself
- **not guaranteed** to arrive if the client disconnects
- scoped to a specific `roomName`, which corresponds to a broadcast channel
This design keeps latency extremely low, but it means you should use the `onMessage` callback if you want to store messages permanently or show chat history on page load.
## Usage
### Basic usage
```html
```
### With initial messages
```html
```
### Storing messages
```html
```
## Features
- Real-time message synchronization
- Message persistence support with `onMessage` and `messages` props
- Customizable message appearance
- Automatic scroll-to-bottom on new messages
- Room-based isolation for scoped conversations
- Low-latency updates using Supabase Realtime
## Props
| Prop | Type | Description |
| ------------ | ----------------------------------- | ------------------------------------------------------------- |
| `roomName` | `string` | Unique identifier for the shared chat room. |
| `username` | `string` | Name of the current user; used to identify message senders. |
| `onMessage?` | `(messages: ChatMessage[]) => void` | Optional callback to handle messages, useful for persistence. |
| `messages?` | `ChatMessage[]` | Optional initial messages to display in the chat. |
### ChatMessage type
```typescript
interface ChatMessage {
id: string
content: string
user: {
name: string
}
createdAt: string
}
```
## Further reading
- [Realtime Broadcast](https://supabase.com/docs/guides/realtime/broadcast)
- [Realtime authorization](https://supabase.com/docs/guides/realtime/authorization)
- [Getting started with Realtime](https://supabase.com/docs/guides/realtime/getting_started)
- [Broadcast from the database](https://supabase.com/docs/guides/realtime/broadcast#broadcast-from-the-database)
- [Broadcast replay](https://supabase.com/docs/guides/realtime/broadcast#broadcast-replay)
- [Realtime limits](https://supabase.com/docs/guides/realtime/limits)
- [Realtime message usage and billing](https://supabase.com/docs/guides/platform/manage-your-usage/realtime-messages)
- [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
- [multiplayer.dev, a live Realtime demo](https://multiplayer.dev)