SupabaseS
Supabase4y ago
Oak

(solved) Realtime subscriptions not working with RLS?

It seems that Realtime subscriptions are not working properly with some RLS policies.
They work as supposed if RLS is completely disabled.
Normal queries (not subscriptions), e.g. SELECT work as expected w/ and w/o RLS policies.

Maybe I am missing something here.

For example:
import { supabaseClient } from '@supabase/auth-helpers-nextjs' // version 0.2.7

// [...]

useEffect(() => {
    const subscription = supabaseClient
      .from('TABLE_NAME')
      .on('*', async (payload) => {
          // do something...
        }
      )
      .subscribe()

    return () => {      supabaseClient.removeSubscription(subscription)
    };

  }, []);

// [...]


If I try to apply a simple RLS policy, like the following, the subscription above does not work anymore:
CREATE POLICY "TEST_POLICY" ON "public"."TABLE_NAME"
AS PERMISSIVE FOR ALL
TO public
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id)


Any ideas?
Was this page helpful?