supabase: Realtime Subscriptions not working locally
Bug report
Describe the bug
“SUBSCRIBED” is returned to the client side, but the event cannot be listen. and I don’t know why, but the realtime.subscription table does not exist in the local DB.
It is working fine in production.
To Reproduce
- Checked “Enable Realtime” for the table in local Supabase Studio
- Write the following code
'use client';
import { createBrowserSupabaseClient } from '@supabase/auth-helpers-nextjs';
export default function Layout({ children }: { children: React.ReactNode }) {
const supabase = createBrowserSupabaseClient({
supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL,
supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
});
useEffect(() => {
const channel = supabase
.channel('companies')
.on(
'postgres_changes',
{
event: 'UPDATE',
schema: 'public',
table: 'companies',
},
(_) => {
console.log('do something');
},
)
.subscribe((status) => {
console.log('Channel status', status);
});
console.log('Channel info', channel);
return () => {
supabase.removeAllChannels();
};
}, []);
return { children };
}
yarn build && yarn start
Expected behavior
Able to listen for changes in the database.
Screenshots

System information
- OS: macOS 13.2
- Browser: chrome 109.0.5414.119
- Version of supabase-js: 2.8.0
- Version of Node.js: 16.14.2
- Version of auth-helpers-nextjs: 0.5.4
- Version of Next.js: 13.1.7-canary.7
- Version of Supabase CLI: 1.38.4
Additional context
Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 21 (2 by maintainers)
Here are the general troubleshooting steps I use when trying to debug Realtime issues, which have prooven pretty helpful so far (some may sound mundane, but I tend to make dumb mistakes myself and this list usually helps me catch them)
.subscribe()method at the end of the function creating the subscription (this is for JavaScript, I am not familiar with other frameworks for Supabase).subscribe()method has a callback for status updates, perhaps the subscription is failing for a network/firewall issue; i.e., something like:supabase.channel(SUBSCRIPTION_ID). ...showing up under thepublic.realtimetable?public.realtimetable?SELECTstill work, but just the Realtime fails?)supabase start)Hope this helps; this list is not exhaustive, but 90% of the time is enough to catch the errors I’m experiencing.
I switched to Supabase triggers and my problem is gone. Webhooks solve the day
Same here, works on hosted but not in local dev
I could fix it for me, I updated the supabase cli, deleted all container did a fresh supabase init and then it worked.
I am on
^1.68.6and was still experiencing the issueIn fact, I have tried almost every version in the last 4 months hoping the my issue would go away but it didn’t.
With the exact same environment setup steps, realtime just sometimes worked and sometimes didn’t in, seemingly random fashion.