Guard Supabase realtime channel usage to prevent runtime errors

cgen-2bd999acc01d4c88aea6ab918f2ea3f9
This commit is contained in:
Builder.io 2025-09-28 00:17:17 +00:00
parent d3d22d69ef
commit abaee59965

View file

@ -367,7 +367,11 @@ export const realtimeService = {
userId: string, userId: string,
callback: (notification: any) => void, callback: (notification: any) => void,
) { ) {
return supabase const client: any = supabase as any;
if (!client || typeof client.channel !== "function") {
return { unsubscribe: () => {} } as any;
}
return client
.channel(`notifications:${userId}`) .channel(`notifications:${userId}`)
.on( .on(
"postgres_changes", "postgres_changes",
@ -383,7 +387,11 @@ export const realtimeService = {
}, },
subscribeToCommunityPosts(callback: (post: any) => void) { subscribeToCommunityPosts(callback: (post: any) => void) {
return supabase const client: any = supabase as any;
if (!client || typeof client.channel !== "function") {
return { unsubscribe: () => {} } as any;
}
return client
.channel("community_posts") .channel("community_posts")
.on( .on(
"postgres_changes", "postgres_changes",