Thomas Allmer
05/25/2023, 10:36 AMsql
CREATE POLICY "Enable select for users based on user_id" ON "public"."rlt-test"
AS PERMISSIVE FOR SELECT
TO public
USING (auth.uid() = user_id)
Data looks something like this (with user_id simplified)
| id | name | user_id |
| --- | ----------- | ------- |
| 1 | John Doe | 1 |
| 2 | Jane Doe | 1 |
| 3 | Susan Smith | 2 |
so now if I do a select via the api with the user_id 1 logged in I get
- John
- Jane
if I do a select * from test
then I get
- John
- Jane
- Susan
Can I execute an sql query that will give me the same result as the API?
e.g. maybe somehow set the values that are used within auth.uid()
an idea
BEGIN;
SET LOCAL auth.jwt = '...';
SELECT * from test;
COMMIT;
it sadly does not work as I don't know which values to set... and if it can even be set that way 😅
anyone got any ideas?silentworks
05/25/2023, 11:46 AMsql
set local role authenticated;
set local "request.jwt.claim.sub" to 'user_uuid_goes_here';
Thomas Allmer
05/25/2023, 1:03 PMvick
05/25/2023, 1:40 PMThomas Allmer
05/25/2023, 5:57 PM