Guard Supabase realtime channel usage to prevent runtime errors
cgen-2bd999acc01d4c88aea6ab918f2ea3f9
This commit is contained in:
parent
d3d22d69ef
commit
abaee59965
1 changed files with 10 additions and 2 deletions
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue