- ✅
client/src/lib/supabase.ts- Supabase client for frontend - ✅
client/src/hooks/useRealtimeSubscription.ts- Reusable Realtime hook - ✅
client/src/components/payments/PaymentsTable.tsx- Example implementation
- ✅
REALTIME_GUIDE.md- Complete implementation guide - ✅
REALTIME_QUICKSTART.tsx- Quick reference examples - ✅ Updated
.env.examplewith frontend Supabase config
Local Development (.env file):
# Add these to your .env file (use same values as backend)
VITE_SUPABASE_URL=https://your-project-id.supabase.co
VITE_SUPABASE_ANON_KEY=your_anon_key_hereVercel Dashboard:
- Go to your Vercel project settings
- Navigate to Environment Variables
- Add:
VITE_SUPABASE_URL= Your Supabase URLVITE_SUPABASE_ANON_KEY= Your Supabase anon key (NOT service role key)
- Open your Supabase Dashboard
- Go to Database → Replication
- Enable replication for these tables:
- ☐
payments - ☐
properties - ☐
units - ☐
tenants - ☐
leases
- ☐
Add this single line to components that need real-time updates:
import { useRealtimeSubscription } from '@/hooks/useRealtimeSubscription';
// In your component function:
useRealtimeSubscription('table_name', ['queryKey']);- Open your dashboard in two browser windows side by side
- In one window, add/edit/delete a record (e.g., a payment)
- Watch the other window update automatically! ✨
Here's where you should add Realtime subscriptions:
-
Payments -
client/src/pages/dashboard/landlord-payments.tsxuseRealtimeSubscription('payments', ['payments']);
-
Dashboard Stats -
client/src/components/SimpleDashboard.tsxuseRealtimeSubscription('properties', ['properties']); useRealtimeSubscription('payments', ['payments']);
-
Tenants -
client/src/pages/dashboard/landlord-tenants.tsxuseRealtimeSubscription('tenants', ['tenants']);
-
Leases -
client/src/pages/dashboard/landlord-leases.tsxuseRealtimeSubscription('leases', ['leases']);
-
Properties -
client/src/pages/dashboard/landlord-properties.tsxuseRealtimeSubscription('properties', ['properties']);
-
Units -
client/src/pages/dashboard/landlord-units.tsxuseRealtimeSubscription('units', ['units']);
- Environment variables added (local + Vercel)
- Supabase Realtime enabled for tables
- Added subscription to at least one component
- Deployed to Vercel
- Tested in browser console (see
[Realtime]logs) - Tested dual browser windows (see automatic updates)
Show a subtle indicator when data is refreshing:
const { data, isFetching } = useQuery({...});
return (
<div className="relative">
{isFetching && (
<div className="absolute top-2 right-2">
<div className="h-2 w-2 rounded-full bg-primary animate-pulse" />
</div>
)}
{/* Your content */}
</div>
);Notify users when data updates:
import { useToast } from '@/hooks/use-toast';
const { toast } = useToast();
useEffect(() => {
const channel = supabase.channel('payments_changes')
.on('postgres_changes', { event: '*', schema: 'public', table: 'payments' },
(payload) => {
queryClient.invalidateQueries(['payments']);
toast({
title: "Payment Updated",
description: "The payments list has been updated.",
});
}
)
.subscribe();
return () => { supabase.removeChannel(channel); };
}, []);✨ Instant Updates - No page refresh needed 🔄 Multi-User Sync - All users see changes in real-time 🎯 Simple Integration - Just one line per component 🧹 Auto Cleanup - No memory leaks 📱 Works Everywhere - Desktop, tablet, mobile 🚀 Better UX - Users love seeing live data
- Check that
VITE_SUPABASE_URLandVITE_SUPABASE_ANON_KEYare set - Restart your dev server after adding env vars
- In Vercel, redeploy after adding env vars
- Check that Realtime is enabled for the table in Supabase Dashboard
- Verify table name matches exactly (case-sensitive)
- Check browser console for connection errors
- Verify query key matches exactly
- Check that TanStack Query is configured correctly
- Look for
[Realtime] Invalidated query keyin console
- Each component creates its own channel - this is normal
- Channels are cleaned up automatically on unmount
- Don't reuse channel names across different tables
- See
REALTIME_GUIDE.mdfor complete documentation - See
REALTIME_QUICKSTART.tsxfor code examples - Supabase Realtime Docs
- TanStack Query Docs
You're all set! Your dashboard will now update in real-time. 🎉