Drizzle TeamDT
Drizzle Teamโ€ข10mo ago
hussam_3h

RLS doesn't work when managing policies with Drizzle?

This is taking to long to understand and I would be grateful for some help!!!

I have my schema distributed between a number of different files grouped by the table's functions/needs. All these files are in my
src/schemas
directory. One of these files is dedicated for policies. Nothing crazy. Something like image 1.

userProfiles
for example is correctly being imported โœ…, drizzle-kit check passes with flying colors โœ…, a push or a migrate call runs smoothly โœ… and everything is being created in Supabase as expected โœ…. Or so I think? ๐Ÿค”

I am following @rphlmr โšก 's
createDrizzle
flow in his SupaSecureSlack example nearly exactly based on my app's needs. Here's whats done so far:

  1. tables created with
    .enableRls()
  2. policy is being added in the policies file similar to the example above.
  3. new role for
    rls_client
    was created and is being used for the
    client
    connection
  4. tables are seeded with dummy rows
  5. using
    createDrizzle
    to create a
    createDrizzleSupabaseClient()
    function exactly like the example.
  6. drizzle config looks like Image 2
The issue:
when running
db.rls((tx)=> tx.select().from(userProfiles)
as an example, I get zero rows back. Running
db.admin.select().from(useProfiles)
returns the right rows. So RLS is kinda working, but not really, because I definitely have the right policy. I can see it was created in Supabase. BUT, if I add a new policy directly inside of Supabase UI, exactly similar to the one already exists, then rls works. Can someone make it make sense? :nomore: ๐Ÿฅน
image.png
image.png
Was this page helpful?