ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseโ€ข4y agoโ€ข
18 replies
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)
    };

  }, []);

// [...]
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)
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?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Realtime subscriptions not working
SupabaseSSupabase / help-and-questions
8mo ago
Realtime not working with RLS
SupabaseSSupabase / help-and-questions
4y ago
Realtime RLS not working with anon user
SupabaseSSupabase / help-and-questions
3y ago
Realtime not working with Custom Jwt with RLS
SupabaseSSupabase / help-and-questions
3mo ago