name: supabase-realtime
Installation
Details
Usage
After installing, this skill will be available to your AI coding assistant.
Verify installation:
npx agent-skills-cli listSkill Instructions
name: supabase-realtime description: Apply when implementing real-time features: live updates, presence, broadcast messages, or database change subscriptions. version: 1.0.0 tokens: ~600 confidence: high sources:
- https://supabase.com/docs/guides/realtime
- https://supabase.com/docs/reference/javascript/subscribe last_validated: 2025-01-10 next_review: 2025-01-24 tags: [supabase, realtime, websocket, database]
When to Use
Apply when implementing real-time features: live updates, presence, broadcast messages, or database change subscriptions.
Patterns
Pattern 1: Database Changes Subscription
// Source: https://supabase.com/docs/guides/realtime
import { useEffect } from 'react';
import { supabase } from '@/lib/supabase';
function useRealtimeMessages(roomId: string) {
const [messages, setMessages] = useState<Message[]>([]);
useEffect(() => {
// Initial fetch
supabase.from('messages').select('*').eq('room_id', roomId)
.then(({ data }) => setMessages(data || []));
// Subscribe to changes
const channel = supabase
.channel(`room:${roomId}`)
.on('postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'messages', filter: `room_id=eq.${roomId}` },
(payload) => setMessages((prev) => [...prev, payload.new as Message])
)
.subscribe();
return () => { supabase.removeChannel(channel); };
}, [roomId]);
return messages;
}
Pattern 2: Presence (Who's Online)
// Source: https://supabase.com/docs/guides/realtime/presence
const [onlineUsers, setOnlineUsers] = useState<User[]>([]);
useEffect(() => {
const channel = supabase.channel('online-users');
channel
.on('presence', { event: 'sync' }, () => {
const state = channel.presenceState();
const users = Object.values(state).flat() as User[];
setOnlineUsers(users);
})
.subscribe(async (status) => {
if (status === 'SUBSCRIBED') {
await channel.track({ user_id: currentUser.id, name: currentUser.name });
}
});
return () => { supabase.removeChannel(channel); };
}, [currentUser]);
Pattern 3: Broadcast (Client-to-Client)
// Source: https://supabase.com/docs/guides/realtime/broadcast
const channel = supabase.channel('cursor-positions');
// Send cursor position
const sendCursor = (x: number, y: number) => {
channel.send({
type: 'broadcast',
event: 'cursor',
payload: { x, y, userId: currentUser.id },
});
};
// Receive cursor positions
channel
.on('broadcast', { event: 'cursor' }, ({ payload }) => {
setCursors((prev) => ({ ...prev, [payload.userId]: payload }));
})
.subscribe();
Pattern 4: All Change Events
// Source: https://supabase.com/docs/reference/javascript/subscribe
const channel = supabase
.channel('table-changes')
.on('postgres_changes',
{ event: '*', schema: 'public', table: 'posts' },
(payload) => {
if (payload.eventType === 'INSERT') handleInsert(payload.new);
if (payload.eventType === 'UPDATE') handleUpdate(payload.new);
if (payload.eventType === 'DELETE') handleDelete(payload.old);
}
)
.subscribe();
Anti-Patterns
- No cleanup - Always
removeChannelon unmount - Subscribing to entire table - Use filters to limit data
- No error handling - Handle subscription errors
- Missing RLS - Realtime respects RLS policies
Verification Checklist
- Channel cleanup in useEffect return
- Filters applied to subscriptions
- Initial data fetched before subscribe
- RLS policies allow realtime access
- Error state handling for subscription failures
More by majiayu000
View allEthereum development with foundry (forge, cast, anvil)
Framework for developing, testing, and deploying trading strategies for prediction markets. Use when creating new strategies, implementing signals, or building backtesting logic.
Project management orchestration for website design and development projects. Use this skill when coordinating multi-agent website projects that require design, frontend development, quality control, accessibility compliance, SEO optimization, and performance analysis. Specifically use for (1) Planning website project workflows, (2) Coordinating design and development agents, (3) Enforcing quality gates and standards, (4) Managing project risks and timelines, (5) Handling stakeholder communication, (6) Ensuring WCAG AAA accessibility compliance, (7) Australian Consumer Law compliance for e-commerce sites, (8) Mobile-first responsive design enforcement.
remotely orchestrate a (chromium) browser to utilize web apps
