RLS not working when connecting using Database connection string with Drizzle ORM
I have this 
connection.ts 
It outputs the user details that is used to connect to the database. It has current_user: 'postgres', rolname: 'postgres', rolbypassrls: true. How can i connect using some other user that respects RLS policies?5 Replies
Drizzle ORM - Row-Level Security (RLS)
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
When I try to query a table that has a SELECT RLS policy setup using Drizzle ORM like
It returns all the rows and not just the ones it should. BTW this is what my rls helper function looks like
Did you use the Drizzle doc for roles I linked?
You seem to be running as Postgres role which will not obey RLS.
If you are not using the Supabase approach in the docs... https://orm.drizzle.team/docs/rls#using-with-supabase
that sets your user role as part of the transaction, then you will need to have another role created to signin from drizzle.  That role would need password and not have bypass RLS set.
You seem to be setting your own user_id in app.current_user_id and I assume are checking that setting in RLS NOT using auth.uid() or auth.jwt().
If so then you do need a user role connecting to the database that does no bypass RLS.
Drizzle ORM - Row-Level Security (RLS)
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
I am setting app.current_user_id = user_id because I am using Better-Auth (not Supabase Auth) for user authentication. I am getting user_id like this 
The project table scheme with RLS policy looks like this.
The policies  look good at quick glance for using that setting.
You need to come up with a login user (other than postgres)  with RLS bypass off.  Not postgres role.  OR in the guide I linked it shows how to change the role in the transaction from postgres role to another role like authenticated (stealing a SB one) or one you create.
I don't use Drizzle though so really don't know the syntax to do what you need to do.  But in your first post you said you are postgres user/role which won't work with RLS.
