From 63e8370991e87bf4ff40e3cf26c66630e33c7ed2 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 20:39:37 +0000 Subject: [PATCH] Refactor realtime hooks --- src/integrations/supabase/types.ts | 4 ++++ ...6_30f32ec3-acb6-4155-b237-de0d59cce0bf.sql | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 supabase/migrations/20251002203926_30f32ec3-acb6-4155-b237-de0d59cce0bf.sql diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index e99ca3ed..0fbb8cf6 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -2182,6 +2182,10 @@ export type Database = { Args: { _user_id: string } Returns: boolean } + check_realtime_access: { + Args: Record + Returns: boolean + } extract_cf_image_id: { Args: { url: string } Returns: string diff --git a/supabase/migrations/20251002203926_30f32ec3-acb6-4155-b237-de0d59cce0bf.sql b/supabase/migrations/20251002203926_30f32ec3-acb6-4155-b237-de0d59cce0bf.sql new file mode 100644 index 00000000..3b965277 --- /dev/null +++ b/supabase/migrations/20251002203926_30f32ec3-acb6-4155-b237-de0d59cce0bf.sql @@ -0,0 +1,19 @@ +-- Phase 1: Fix Realtime Subscriptions - Add realtime access helper function +-- Note: Realtime schema permissions are managed by Supabase automatically +-- Tables are already in the supabase_realtime publication with REPLICA IDENTITY FULL + +-- Create a function to verify realtime access for moderators +CREATE OR REPLACE FUNCTION public.check_realtime_access() +RETURNS boolean +LANGUAGE plpgsql +STABLE SECURITY DEFINER +SET search_path = public +AS $$ +BEGIN + -- Check if user is a moderator (can access realtime moderation features) + RETURN is_moderator(auth.uid()); +END; +$$; + +-- Add comment to the function +COMMENT ON FUNCTION public.check_realtime_access() IS 'Checks if the current user has permission to access realtime moderation features. Returns true for moderators, admins, and superusers.'; \ No newline at end of file