any way to compare search parameters on RLS?

hi, fast question... any way to compare search parameters on rls? like:
supaClient.client.from('participant')
.update({
user: ''
})
.eq('invite_code', invite_code)
supaClient.client.from('participant')
.update({
user: ''
})
.eq('invite_code', invite_code)
CREATE POLICY "participant_user_link_update" ON public.participant
FOR UPDATE TO authenticated
USING (true)
WITH CHECK (
invite_code = <MY_EQ_QUERY_VALUE> AND user IS NULL
);
CREATE POLICY "participant_user_link_update" ON public.participant
FOR UPDATE TO authenticated
USING (true)
WITH CHECK (
invite_code = <MY_EQ_QUERY_VALUE> AND user IS NULL
);
ia assistant recommend me use a headers... but... I don't like use this so much...
CREATE POLICY "participant_user_link_update" ON participant
FOR UPDATE TO authenticated
USING (true)
WITH CHECK (
invite_code = (
SELECT current_setting('request.headers', true)::jsonb->>'x-invite-code'
) AND user IS NULL
);
CREATE POLICY "participant_user_link_update" ON participant
FOR UPDATE TO authenticated
USING (true)
WITH CHECK (
invite_code = (
SELECT current_setting('request.headers', true)::jsonb->>'x-invite-code'
) AND user IS NULL
);
and I not sure if I can use something like
current_setting('request.querys', true)::jsonb->>'invite_code')
current_setting('request.querys', true)::jsonb->>'invite_code')
2 Replies
garyaustin
garyaustin3w ago
No. Headers is the only way with a normal call. You could use an RPC call to a Postgres function. RLS can only see data in the row before (USING) or after (WITH CHECK).
OsirisFrik
OsirisFrikOP3w ago
well tnks 😁

Did you find this page helpful?