https://supabase.com/ logo
Join Discord
Powered by
# sql
  • p

    Prefix

    12/26/2021, 11:58 PM
    I have an issue opened for this bug in the real-time repo if you want to add your findings! https://github.com/supabase/realtime/issues/213
  • g

    Gary, el Pingüino Artefacto

    12/27/2021, 5:16 AM
    any example for a multi tenant (sass design) using supabase and dynamic schemas? Maybe using different tenants for db for custom table, idk
  • t

    TremalJack

    12/27/2021, 9:24 AM
    from what I saw from ur code, you are missing "auth", instead "uid()" you have to call "auth.uid()"
    Copy code
    is_member_of_list(auth.uid(), list_id)
  • k

    ktosiek

    12/27/2021, 9:33 AM
    adding RLS through the Supabase UI drops the "auth.", I think "auth" is in the path
  • t

    TremalJack

    12/27/2021, 9:35 AM
    this isn't possible because the defaults policies have access to auth.uid() , auth.email() and auth.role() functions, and all them are custom function created on auth schema
  • t

    TremalJack

    12/27/2021, 9:36 AM
    so... the RLS have access to the functions, the only difference I have find atm is the location, the supabase default SQL functions are under auth schema, the one we are trying to use on RLS is in public schema
  • t

    TremalJack

    12/27/2021, 9:59 AM
    I made an issue ticket about RLS with Custom SQL functions https://github.com/supabase/supabase/issues/4683 @User let's see if someone can help us
  • t

    TremalJack

    12/27/2021, 2:48 PM
    @User I have some news, I did more test, so... I discover that: if the SQL function is declared with the option SECURITY DEFINER, then the function is triggered by RLS but not from standard queries: this explain why the standard queries work and realtime stop to work if the SQL function is declared without the option SECURITY DEFINER, then the function is triggered at every query (standard queries too) and then I got the error: max_stack_depth error in postgresql so.... if my think are right, when the function is defined with SECURITY DEFINER and the realtime is triggered, he go in error max_stack_depth, but is internal then we not see any kind of result... the fast solution is increase the max_stack_depth but I will not like do it, I think we need work to optimize the query inside the function to avoid many recursive checks
  • t

    TremalJack

    12/27/2021, 2:57 PM
    anyway is strange because my function is a simple select:
    Copy code
    SELECT EXISTS (
      SELECT 1
      FROM channel_users cu
      WHERE cu.channel_id::int8 = _channel_id::int8
      AND cu.user_mail::text = _user_email::text
    );
    and I get immediatly the error max_stack_depth from a simple select query:
    Copy code
    const lastChannelMessageRead = await this.supabase.from('channel_users').select('channel_id,last_message_read').eq('user_mail',this.data.user_loged.user.email)
  • k

    ktosiek

    12/27/2021, 2:59 PM
    Are you selecting from the table your RLS rule is protecting?
  • t

    TremalJack

    12/27/2021, 3:00 PM
    yes
  • t

    TremalJack

    12/27/2021, 3:02 PM
    damn, Im an idiot lol
  • k

    ktosiek

    12/27/2021, 3:02 PM
    well, that's why you need SECURITY DEFINER 🙂
  • t

    TremalJack

    12/27/2021, 3:02 PM
    if the the table is the one protected he will not be able to select all, and will die in recursive depth to determinate the rows lmao
  • t

    TremalJack

    12/27/2021, 3:03 PM
    yes but if I set Security Definer the regular queries will work but the realtime will die always
  • t

    TremalJack

    12/27/2021, 3:03 PM
    so... this is the mistery xD
  • t

    TremalJack

    12/27/2021, 3:08 PM
    with the SECURITY DEFINER all work... I retrieve the data, I subscribe to the realtime task ect, but at the moment to execute an action would trigger the realtime, this will be never emitting
  • t

    TremalJack

    12/27/2021, 3:13 PM
    to explain, I have an table: channel_users this table is a link between chat channels and users profiles, in this table is present an column: "isTyping" and the table is enabled for the realtime. when an user is typing I go to update the boolean to True on column isTyping, this trigger the UPDATE event on realtime, if I set the RLS policy to "true" I get the payload from realtime subscription, if I set my function to the policy, I will not get the payload
  • t

    TremalJack

    12/27/2021, 3:14 PM
    but the rest will work lmao
  • t

    TremalJack

    12/27/2021, 3:39 PM
    any idea?
  • l

    lorencerri

    12/27/2021, 8:33 PM
    Hello, I'm having trouble creating this RLS policy, and was curious if someone could give me some pointers. I have a
    public.identities
    table with staff
    (boolean)
    & uid
    (auth.user foreign key)
    columns. Essentially, I want to check if that identity has the staff boolean value to true before being able to edit this table. I've tried these two, although they both seem to produce errors near the beginning of the expression: EDIT: The following seemed to work, although I'm not sure if it's the best way of doing it
    Copy code
    sql
    exists (
      select staff from public.identities
      where public.identities.uid = auth.uid()
      and public.identities.staff = true
    )
  • b

    bs-clerk

    12/27/2021, 9:21 PM
    i need some help debugging row level security... I have a policy auth.user_id() = user_id, however, it's not passing. Is there any way to see what JWT is getting sent up? can't figure out where its not working
  • c

    chipilov

    12/27/2021, 9:22 PM
    I don't think there is auth.user_id() function...did you mean auth.uid()?
  • b

    bs-clerk

    12/27/2021, 9:23 PM
    i was following some tutorial.. it had me create auth.user_id()
  • b

    bs-clerk

    12/27/2021, 9:24 PM
    will auth.uid() pull off the userId claim of the jwt sent w/ the request?
  • c

    chipilov

    12/27/2021, 9:24 PM
    yes
  • b

    bs-clerk

    12/27/2021, 9:25 PM
    This is what im trying to follow. https://auth0.com/blog/using-nextjs-and-auth0-with-supabase/#Supabase
  • b

    bs-clerk

    12/27/2021, 9:25 PM
    seems like it expects auth.uid() to be a UUID whereas mines set as text
    c
    • 2
    • 20
  • c

    chasers

    12/28/2021, 1:25 AM
    Currently that field is basically the
    where
    portion of a sql statement. Soon it will allow you to pass full sql to query your logs with. Iterating through that whole UI more at the moment.
    c
    • 2
    • 1
  • t

    TremalJack

    12/28/2021, 9:08 AM
    @User https://github.com/supabase/supabase/issues/4683#issuecomment-1001708800
1...293031...52Latest