Realtime¶
Publication Configuration¶
The supabase_realtime publication includes the following tables for real-time subscriptions:
ALTER PUBLICATION supabase_realtime ADD TABLE orders;
ALTER PUBLICATION supabase_realtime ADD TABLE order_status_history;
ALTER PUBLICATION supabase_realtime ADD TABLE notifications;
ALTER PUBLICATION supabase_realtime ADD TABLE messages;
ALTER PUBLICATION supabase_realtime ADD TABLE chats;
ALTER PUBLICATION supabase_realtime ADD TABLE offers;
ALTER PUBLICATION supabase_realtime ADD TABLE promotions;
Usage in Apps¶
Flutter (Mobile)¶
// Orders real-time stream
supabase
.from('orders')
.stream(primaryKey: ['id'])
.eq('user_id', userId)
.order('created_at', ascending: false);
// Chat rooms stream
supabase
.from('chats')
.stream(primaryKey: ['id'])
.in('id', myChatIds);
// Messages stream
supabase
.from('messages')
.stream(primaryKey: ['id'])
.eq('chat_id', chatId);
React (Web)¶
// Notification subscription
const subscription = supabase
.channel('notifications')
.on('postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'notifications',
filter: `user_id=eq.${userId}` },
(payload) => {
// Show toast or badge update
dispatch(addNotification(payload.new));
}
)
.subscribe();
// Order changes subscription
supabase
.channel('orders')
.on('postgres_changes',
{ event: '*', schema: 'public', table: 'orders' },
() => { dispatch(fetchOrders()); }
)
.subscribe();
Broadcast Channels¶
| Channel | Table | Events | Purpose |
|---|---|---|---|
orders-channel |
orders | * |
Real-time order list updates |
notifications |
notifications | INSERT | New notification alerts |
chat-{chatId} |
messages | INSERT | Live chat messages |
| N/A | chats | UPDATE | Last message preview update |
Related¶
- RLS Policies — Policies governing real-time access