LovableSupabaseIntermediate8 min read

How to Add Real-Time Features to Your Lovable App

Add live updates, real-time notifications, and collaborative features to your Lovable app using Supabase Realtime.

Before you start

  • A Lovable app connected to Supabase
  • At least one database table to subscribe to

Step by step

1

Enable Realtime for your table

In the Supabase dashboard, enable Realtime on the table you want to listen to.

-- In Supabase SQL Editor:
ALTER PUBLICATION supabase_realtime ADD TABLE messages;

-- Or in Dashboard:
-- Table Editor → messages → Enable Realtime
2

Create a real-time listener

Ask Lovable to subscribe to database changes and update the UI live.

Paste this into Lovable:

Create a real-time chat component that:
1. Subscribes to INSERT events on the 'messages' table using Supabase Realtime
2. When a new message arrives, adds it to the message list without refreshing
3. Loads existing messages on component mount
4. Unsubscribes from the channel when the component unmounts
5. Shows new messages with a subtle slide-in animation
3

Add presence tracking

Show who's currently online using Supabase Presence.

Paste this into Lovable:

Add online presence to the chat:
1. When a user opens the chat, track their presence on a 'chat-room' channel
2. Show a green dot next to online users
3. Display 'X users online' at the top
4. Remove the user from presence when they leave the page
5. Update the online list in real-time as users join/leave
4

Add typing indicators

Show when other users are typing a message.

Paste this into Lovable:

Add typing indicators to the chat:
1. When the user types in the input field, broadcast a 'typing' event via Supabase channel
2. Stop broadcasting 2 seconds after the user stops typing
3. Show 'User is typing...' below the messages when someone else is typing
4. Use Supabase broadcast (not database) for performance
5

Handle real-time for notifications

Use real-time subscriptions for in-app notifications.

Paste this into Lovable:

Create a notification bell component that:
1. Subscribes to INSERT events on a 'notifications' table for the current user
2. Shows a red badge with unread count
3. Clicking opens a dropdown with notification list
4. Marking as read updates the database
5. New notifications play a subtle sound

Common errors

Realtime subscription not receiving events

Realtime isn't enabled on the table, or RLS is blocking.

Fix: Run ALTER PUBLICATION supabase_realtime ADD TABLE your_table. Also check that RLS policies allow SELECT for the user.

Duplicate messages appearing

The component subscribes multiple times due to re-renders.

Fix: Move the subscription to a useEffect with proper cleanup. Return the unsubscribe function.

Presence not updating

The user's presence state isn't being synced.

Fix: Call channel.track() with the user's info after joining the channel. Make sure you pass a unique user identifier.

Related guides

Weekly Newsletter

Get next week's fix before you need it.

Join developers getting weekly vibe coding tips, error fixes, and tool updates.

Subscribe on Substack →