.claude/skills/supabase-realtime/SKILL.md
Supabase Realtime for live subscriptions, broadcasts, and presence. Use when implementing real-time features, live updates, chat, or online presence tracking.
npx skillsauth add adaptationio/skrillz supabase-realtimeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Live subscriptions, broadcasts, and presence.
| Feature | Use Case | |---------|----------| | Postgres Changes | Database row changes (INSERT, UPDATE, DELETE) | | Broadcast | Client-to-client messaging (chat, notifications) | | Presence | Track online users, typing indicators |
-- Enable realtime for a table
ALTER PUBLICATION supabase_realtime ADD TABLE posts;
-- Enable for specific columns only
ALTER PUBLICATION supabase_realtime ADD TABLE posts (id, title, status);
const channel = supabase
.channel('posts-changes')
.on(
'postgres_changes',
{ event: '*', schema: 'public', table: 'posts' },
(payload) => {
console.log('Change:', payload)
// payload.eventType: 'INSERT' | 'UPDATE' | 'DELETE'
// payload.new: new row data
// payload.old: previous row data (UPDATE/DELETE only)
}
)
.subscribe()
// INSERT only
const channel = supabase
.channel('new-posts')
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'posts' },
(payload) => console.log('New post:', payload.new)
)
.subscribe()
// UPDATE only
const channel = supabase
.channel('updated-posts')
.on(
'postgres_changes',
{ event: 'UPDATE', schema: 'public', table: 'posts' },
(payload) => console.log('Updated:', payload.old, '->', payload.new)
)
.subscribe()
// DELETE only
const channel = supabase
.channel('deleted-posts')
.on(
'postgres_changes',
{ event: 'DELETE', schema: 'public', table: 'posts' },
(payload) => console.log('Deleted:', payload.old)
)
.subscribe()
// Only changes where status = 'published'
const channel = supabase
.channel('published-posts')
.on(
'postgres_changes',
{
event: '*',
schema: 'public',
table: 'posts',
filter: 'status=eq.published'
},
(payload) => console.log('Published post change:', payload)
)
.subscribe()
// Filter by user_id
const channel = supabase
.channel('user-posts')
.on(
'postgres_changes',
{
event: '*',
schema: 'public',
table: 'posts',
filter: `user_id=eq.${userId}`
},
(payload) => console.log('User post change:', payload)
)
.subscribe()
const channel = supabase
.channel('all-changes')
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'posts' },
(payload) => console.log('New post:', payload.new)
)
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'comments' },
(payload) => console.log('New comment:', payload.new)
)
.subscribe()
const channel = supabase.channel('room-1')
// Subscribe first
channel.subscribe((status) => {
if (status === 'SUBSCRIBED') {
// Send message
channel.send({
type: 'broadcast',
event: 'message',
payload: { text: 'Hello everyone!' }
})
}
})
const channel = supabase
.channel('room-1')
.on('broadcast', { event: 'message' }, (payload) => {
console.log('Received:', payload.payload)
})
.subscribe()
const roomId = 'chat-room-123'
const channel = supabase.channel(roomId)
// Listen for messages
channel
.on('broadcast', { event: 'new-message' }, ({ payload }) => {
console.log(`${payload.username}: ${payload.message}`)
})
.subscribe()
// Send message function
function sendMessage(username, message) {
channel.send({
type: 'broadcast',
event: 'new-message',
payload: { username, message, timestamp: new Date().toISOString() }
})
}
const channel = supabase.channel('online-users')
// Track current user
channel.subscribe(async (status) => {
if (status === 'SUBSCRIBED') {
await channel.track({
user_id: currentUser.id,
username: currentUser.name,
online_at: new Date().toISOString()
})
}
})
const channel = supabase
.channel('online-users')
.on('presence', { event: 'sync' }, () => {
// Get all online users
const state = channel.presenceState()
console.log('Online users:', state)
})
.on('presence', { event: 'join' }, ({ key, newPresences }) => {
console.log('User joined:', newPresences)
})
.on('presence', { event: 'leave' }, ({ key, leftPresences }) => {
console.log('User left:', leftPresences)
})
.subscribe()
// After subscribing
const state = channel.presenceState()
// state is an object keyed by user key
// { "user-123": [{ user_id: "...", username: "...", online_at: "..." }] }
const onlineUsers = Object.values(state).flat()
console.log('Online count:', onlineUsers.length)
await channel.untrack()
import { useEffect, useState } from 'react'
function usePosts() {
const [posts, setPosts] = useState([])
useEffect(() => {
// Initial fetch
supabase.from('posts').select('*').then(({ data }) => {
setPosts(data || [])
})
// Subscribe to changes
const channel = supabase
.channel('posts-realtime')
.on(
'postgres_changes',
{ event: '*', schema: 'public', table: 'posts' },
(payload) => {
if (payload.eventType === 'INSERT') {
setPosts(prev => [...prev, payload.new])
} else if (payload.eventType === 'UPDATE') {
setPosts(prev =>
prev.map(post =>
post.id === payload.new.id ? payload.new : post
)
)
} else if (payload.eventType === 'DELETE') {
setPosts(prev =>
prev.filter(post => post.id !== payload.old.id)
)
}
}
)
.subscribe()
return () => {
supabase.removeChannel(channel)
}
}, [])
return posts
}
import { useEffect, useState } from 'react'
function useOnlineUsers(roomId) {
const [onlineUsers, setOnlineUsers] = useState([])
useEffect(() => {
const channel = supabase
.channel(`room-${roomId}`)
.on('presence', { event: 'sync' }, () => {
const state = channel.presenceState()
setOnlineUsers(Object.values(state).flat())
})
.subscribe(async (status) => {
if (status === 'SUBSCRIBED') {
await channel.track({
user_id: currentUser.id,
username: currentUser.name
})
}
})
return () => {
channel.untrack()
supabase.removeChannel(channel)
}
}, [roomId])
return onlineUsers
}
const channel = supabase
.channel('my-channel')
.on('postgres_changes', { ... }, callback)
.subscribe((status, err) => {
if (status === 'SUBSCRIBED') {
console.log('Connected!')
} else if (status === 'CLOSED') {
console.log('Disconnected')
} else if (status === 'CHANNEL_ERROR') {
console.error('Error:', err)
}
})
SUBSCRIBED - Successfully connectedTIMED_OUT - Connection timed outCLOSED - Channel closedCHANNEL_ERROR - Error occurredawait supabase.removeChannel(channel)
await supabase.removeAllChannels()
Realtime respects RLS policies. Users only see changes they have access to.
-- Policy for realtime
CREATE POLICY "Users see own posts realtime"
ON posts FOR SELECT
TO authenticated
USING (auth.uid() = user_id);
For broadcast and presence, use RLS on realtime.messages:
-- Create policy for channel access
CREATE POLICY "Channel access"
ON realtime.messages
FOR ALL
TO authenticated
USING (
realtime.topic() LIKE 'room-' || auth.uid()::text || '%'
);
To access old record on UPDATE/DELETE:
-- Enable full replica identity
ALTER TABLE posts REPLICA IDENTITY FULL;
| Operator | Example |
|----------|---------|
| eq | filter: 'status=eq.active' |
| neq | filter: 'status=neq.deleted' |
| in | filter: 'status=in.(active,pending)' |
Note: Only 1 filter per subscription is supported.
development
Setup secure web-based terminal access to WSL2 from mobile/tablet via ttyd + ngrok/Cloudflare/Tailscale. One-command install, start, stop, status. Use when you need remote terminal access, web terminal, browser-based shell, or mobile access to WSL2 environment.
development
Complete development workflows where Claude writes the code while Gemini and Codex provide research, planning, reviews, and different perspectives. Claude remains the main developer. Use for complex projects requiring expert planning and multi-perspective reviews.
development
Systematic progress tracking for skill development. Manages task states (pending/in_progress/completed), updates in real-time, reports progress, identifies blockers, and maintains momentum. Use when tracking skill development, coordinating work, or reporting progress.
testing
Comprehensive testing workflow orchestrating functional testing, example validation, integration testing, and usability assessment. Sequential workflow for complete skill testing from examples through scenarios to integration validation. Use when conducting thorough testing, pre-deployment validation, ensuring skill functionality, or comprehensive quality checks.