I made person table that gets row on trigger of new auth user where i make field user_id for auth id and a auto generated uuid for person_id. (I guess thought maybe dont tie person id to auth id in case move account to diff auth user). Anyway for storage I am trying to create a crud policy but I dont believe you can do declare, begin, end
I also have a person_roles table with person_id, role_id like 'admin'
I have auth.uid in policy do i need to use that to get the person id and then check if there is a person_id, 'admin' row in person_roles
How might I accomplish this?
declare
_person_id uuid;
begin
select id from public.persons where user_id = auth.uid()::text into _person_id;
select 1 from public.person_roles where person_id = _person_id and role_id = 'admin';
end;
This is my not correct but gives idea of aim