Pricing Blog

How do you manage table access based on user profile (supabase)?

  • uunicode-1441392355113435258

    unicodes

    1 day ago

    Do you know what is more performant for managing access to supabase tables?

    I'm curios if having one single RLS to manage all SELECT based on each user profile (admin, manager, etc) or having separate RLS.

    I have in my user table a column with this profile type, do you recommend to do something like (SELECT profile FROM users WHERE id = auth.uid()) = "manager" or do you recommend to add at login this information in the JWT and manage the select based on the JWT select. What would be faster, selecting from JWT or from the tables?

    Do you have a better alternative?
  • erikbeus-1441393468294566009

    Erik Beuschau

    1 day ago

    We're not storing much information in the jwt. Supabase is usually fast enough 🙂
  • uunicode-1441394096622014606

    unicodes

    1 day ago

    Thank you @Erik Beuschau , do you recommend one single big RLS to manager SELECT or having multiple RLS SELECT rules? Are them called sync or async?
  • erikbeus-1441394746135285781

    Erik Beuschau

    1 day ago

    I believe Supabase's performance advisor recommends usingn fewer rules. But we often use multiple for clarity. They are called/used before the operation (GET/UPDATE/INSERT) is performed. So synchronously
    🙏1
  • uunicode-1441395523108999279

    unicodes

    1 day ago

    Thank you, Erik, for your input. I wrote this question hoping you would reply, and indeed you was the first one. I appreciate your feedback! 🤩
    🙌1
  • lucasg-1441458320253653142

    Lucas G

    1 day ago

    Adding that having a lot of info in your JWT is faster but has drawbacks.
    You can’t invalidate active JWTs if the user’s data or access ever changes
  • lucasg-1441458592363577397

    Lucas G

    1 day ago

    It’s not as big a deal if you have very short lived tokens but it is if you have for example a week+ long life on them
  • lucasg-1441459064403132497

    Lucas G

    1 day ago

    Multiple RLS policies do slow down queries eventually but it’s not an issue unless you have bigger tables. Supabase gives you recommendations on how to write them
  • Like not directly using auth.uid() etc
  • uunicode-1441555320022237287

    unicodes

    1 day ago

    Thank you @Lucas G . Do you have views without RLS activated? I created a view because I want to grant access based on the view’s "WHERE" select, which works like RLS. However, I can’t activate RLS because it applies the table’s RLS policy, and that policy only allows access for the owner (I don't want to change that), but that red dot is really frustrating. Should I find a solution to views with RLS only activated? I have this visual blockage 😅
  • lucasg-1441558434465185976

    Lucas G

    1 day ago

    No I’d never leave a table without RLS or some type of security layer
  • uunicode-1441558630938837034

    unicodes

    1 day ago

    No, isn't a table, is a view.
  • uunicode-1441559041548488868

    unicodes

    1 day ago

    Like you have users table with rls only for owners. I created a view for users that are public, and toggle public. (In this way I can give access only to a selected columns only and fetch data from other tables too, but not all columns).
  • lucasg-1441559069763834007

    Lucas G

    1 day ago

    Still. A WHERE clause isn’t security.
  • Is the main thing
  • If the table doesn’t have data that should only be viewed by certain people then it doesn’t matter as much
  • lucasg-1441559734065954928

    Lucas G

    1 day ago

    View*
  • uunicode-1441559763040075819

    unicodes

    1 day ago

    How would you proceed in this situation? You have users table and users_jobs, both could be selected only by owner, but in some case if owner want's to share part of the info, you have a view with a select of the users columns and users_jobs columns where users.public = true. Why that where shouldn't be secure?
  • lucasg-1441566084644999198

    Lucas G

    1 day ago

    I'd either add a specific role/key to the public call that has its own RLS policy (like view public items only) or, most likely, I'd use a worker to validate the call and fetch the items from there.
  • uunicode-1441567333629034709

    unicodes

    1 day ago

    I can't use RLS because you don't want to grant visibility on all columns, maybe just first and last name. And a worker, yes, I could use a worker, but it has the same select as I have in the view. On the other hand, a view allows me to add a "foreign key" (not a real foreign key, just a simulation), whereas you can't do that with a worker, a view is much more practical.
  • uunicode-1441567602504892446

    unicodes

    1 day ago

    This is why I'm stuck with that red dot for "safety" even if is very safe, but workarounds (practical ones) are very limited vs View.
  • lucasg-1441568971861131295

    Lucas G

    1 day ago

    It's unsafe in the sense that if the underlying table is known then somebody can just query that table directly since it has no policies. I don't know what the full setup here is obviously so I don't know how "unsafe" it really is.
    I wouldn't say a worker is restricted though. You can pull whatever data you need and return only that, the endpoint is public but it would only return limited data.
  • lucasg-1441569302531674123

    Lucas G

    1 day ago

    And there could still be an RLS policy to protect the table itself.
  • lucasg-1441570258312892590

    Lucas G

    1 day ago

    By worker I mean something like edge functions*
  • uunicode-1441570346825416795

    unicodes

    1 day ago

    Yes, I know.
  • lucasg-1441570419206521073

    Lucas G

    1 day ago

    I stopped using Supabase almost a year ago though I never used edge functions even then lol
  • uunicode-1441571015627899071

    unicodes

    1 day ago

    What I mean si that the table has RLS only for owners, the view doesn't have because there I use where and is a very good select. Adding rls on the view would limit the select to owners only, but without RLS gives me flexibility and help me to keep users table safe in the same time I'm sharing some data in a safe way too but without RLS using a view. @Erik Beuschau what do you think on such case, it worth using views without rls because the view select where is enoght, but the table has rls?
  • lucasg-1441571128572379268

    Lucas G

    1 day ago

    Views use the RLS from the underlying table no?
  • They don't have their own RLS
  • uunicode-1441571177712586816

    unicodes

    1 day ago

    What do you use as main backend/database?
  • lucasg-1441571245480214628

    Lucas G

    1 day ago

    So you do have RLS then
  • uunicode-1441571391689457795

    unicodes

    1 day ago

    exactly, this is why, if you activate an RLS over the views (not on table, because over tables is mandatory always on), you limit your select based on table rls.
  • uunicode-1441571472068837468

    unicodes

    1 day ago

    on the table yes, but not on the view.
  • lucasg-1441571648821133554

    Lucas G

    1 day ago

    Ok you're losing me lol. You're saying the table has RLS but then also saying the table does not have RLS.
  • enabled
  • uunicode-1441571861698969650

    unicodes

    1 day ago

    Here, jobs has RLS (restricted to organization) but if you taggle public and is approved, the view (jobs_published) does a select of all jobs.published = true, and shows only part of necessary tables (jobs, jobs_skills, etc..), not full data of the table (I need just title maybe).
    1441571861506035752-Screenshot_2025-11-22_at_01.30.52.png
  • uunicode-1441572210816057527

    unicodes

    1 day ago

    jobs is table, jobs_publiched is a view. jobs has rls, jobs_published doesn't because is using a where that is limiting access. Like where user.name = 'Lucas'. Only you can view data from jobs_published (the view, not table), and I don't get how you could trick that where from the view.
  • uunicode-1441573382167466094

    unicodes

    1 day ago

    I'm using views here because are very powerful and flexible, but is making me nervous seeing that "Unrestricted" even if is very safe.
  • lucasg-1441606626212843613

    Lucas G

    1 day ago

    Sorry, wasn't home and couldn't continue replying
  • lucasg-1441607524536156242

    Lucas G

    1 day ago

    Again, the "unsafe" thing is relevant. It doesn't sound like the view exposes sensitive data or data that shouldn't be access by unauthorized users so it probably doesn't matter. That Unrestricted tag is there on the UI to let people know that views don't have policies on their own
  • lucasg-1441607854850314454

    Lucas G

    1 day ago

    I pinged the endpoint and can see that there's a position for a "NetSuite Developer". If that's not something I should be able to do that easily then you have your answer lol
  • uunicode-1441658047196958860

    unicodes

    1 day ago

    Is perfectly fine if you can see that data, I’m making it public so anyone can see the published jobs, but you see only that one, in jobs there are more meaning that it works.