https://supabase.com/ logo
I made person table that gets row on trigger of ne...
# help
j
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?
Copy code
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
n
Hello @jar! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
You definitely can't do plpgsql function code in a policy. You might ask in sql section for help on the correct sql.
j
Ah whatever not huge deal for now ill just copy paste my user_id in there. Maybe ill figure this out in future
n
Thread was archived by @jar. Anyone can send a message to unarchive it.