Skip to main content
Build a fully functional real-time chat application with user presence, typing indicators, and instant message delivery using Supabase Realtime.

What You’ll Build

A real-time chat app featuring:
  • Instant message delivery
  • Online user presence
  • Typing indicators
  • Message history
  • User authentication
  • Channel-based conversations

Architecture

This app uses:
  • Supabase Auth for user authentication
  • Supabase Database for message storage
  • Supabase Realtime for live updates
  • Presence for online status
  • Broadcast for typing indicators
1

Create Your Project

  1. Go to supabase.com/dashboard
  2. Create a new project
  3. Wait for the database to be ready
2

Set Up Database Schema

Run this SQL in the SQL Editor:
3

Enable Realtime in Dashboard

  1. Go to DatabaseReplication
  2. Enable replication for:
    • messages table
    • profiles table
  3. Click Save
4

Set Up Your Next.js App

Create a new Next.js app:
Install Supabase:
Create .env.local:
5

Create Supabase Client

Create lib/supabase.ts:
6

Build the Chat Component

Create components/Chat.tsx:
7

Create the Auth Flow

Create app/page.tsx:
8

Run Your Chat App

Start the development server:
Open multiple browser windows at http://localhost:3000 to test real-time messaging!

Key Features Explained

Postgres Changes

Listens for new rows in the messages table:

Presence

Tracks online users in the channel:

Broadcast

Sends ephemeral messages (like typing indicators):

Enhancements

Create a reactions table and use Realtime to sync reactions across clients.
Integrate Supabase Storage to allow users to share images and files.
Create a channels table and let users create/join different chat rooms.
Add 1-on-1 private messaging between users.
Track which messages have been read by each user.

Next Steps

Realtime Presence

Learn more about presence tracking

Broadcast

Master broadcast channels

Postgres Changes

Deep dive into database subscriptions

Storage

Add file sharing to your chat