Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime RLS does not work if I don't explicitly setAuth #1304

Open
bukacdan opened this issue Nov 7, 2024 · 0 comments
Open

Realtime RLS does not work if I don't explicitly setAuth #1304

bukacdan opened this issue Nov 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@bukacdan
Copy link

bukacdan commented Nov 7, 2024

Bug report

Describe the bug

I have valid session in supabase.auth, however if I subscribe to a channel, I'm not getting any data, because of RLS.
If I use supabase.realtime.setAuth with the access token, that has already been in the auth.session, the data starts coming.

To Reproduce

  1. create table public.test with column uid (so the RLS can be set so users can only read their data)
  2. allow realtime
  3. set auth policy so that users can only read their data
  4. sign in user in your codebase, so that you have valid supabase.auth.getSession
const channel = supabase.channel("premium").on(
        'postgres_changes',
        { event: 'UPDATE', schema: 'public', table: 'test'},
        (payload) => {
            console.log("Premium change payload", payload);
        }
    ).subscribe((status, err) => {
        if (err) {
            console.error("Error subscribing to premium channel", err);
        }
        console.log("Subscription status", status);
    })

this code won't reliably receive updates for the signed in user in the public.test table. However if we add something like this, the data starts coming.

    const { data, error } = await supabase.auth.getSession();
    if (error || !data) {
        console.error("Error getting session", error);
        return;
    }
    supabase.realtime.setAuth(data.session.access_token);

Expected behavior

I was expecting that the session is propagated automatically. I only found this reference in documentation, but that's referring to custom tokens, but this happened for regular supabase sign in without no custom tokens. So either the auth should be propagated to realtime automatically or add mention do documentation to always use setAuth for realtime.

System information

  • OS: macOS
  • Browser: electron
  • Version of supabase-js: [2.45.2]
  • Version of Node.js: [16]

Additional context

Add any other context about the problem here.

@bukacdan bukacdan added the bug Something isn't working label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant