Albert [tox/cis]
05/07/2022, 9:51 PMis_admin()
which checks a table where I've stored user ids and roles. All it does is pretty much return exists(select * from user_role where "user" = auth.uid() and role = 'admin'
. In flutter, I tested this and it gives me a true value :). Now, I wanted to apply this to row level policies. It's simple: if someone wants to edit a specific table, is_admin()
just needs to return true however, my requests get rejected all the time. Why?Needle
05/07/2022, 9:51 PMgaryaustin
05/07/2022, 9:58 PMNeedle
05/07/2022, 9:58 PMAlbert [tox/cis]
05/07/2022, 10:00 PMgaryaustin
05/07/2022, 10:00 PMAlbert [tox/cis]
05/07/2022, 10:00 PMAlbert [tox/cis]
05/07/2022, 10:00 PMsecurity invoker
Albert [tox/cis]
05/07/2022, 10:01 PMgaryaustin
05/07/2022, 10:02 PMAlbert [tox/cis]
05/07/2022, 10:02 PMAlbert [tox/cis]
05/07/2022, 10:03 PMcreate or replace function is_admin() returns boolean as $$
begin
if exists(select * from user_role where "user" = auth.uid() and role = 'admin') then return true;
else return false;
end if;
end
$$ language plpgsql security invoker;
Albert [tox/cis]
05/07/2022, 10:04 PMvar x = (await Supabase.instance.client
.rpc('is_admin')
.select()
.execute());
print(x.data);
which prints true
garyaustin
05/07/2022, 10:06 PMAlbert [tox/cis]
05/07/2022, 10:07 PMgaryaustin
05/07/2022, 10:07 PMAlbert [tox/cis]
05/07/2022, 10:08 PMAlbert [tox/cis]
05/07/2022, 10:08 PMAlbert [tox/cis]
05/07/2022, 10:08 PMgaryaustin
05/07/2022, 10:08 PMgaryaustin
05/07/2022, 10:10 PMAlbert [tox/cis]
05/07/2022, 10:10 PMAlbert [tox/cis]
05/07/2022, 10:11 PMAlbert [tox/cis]
05/07/2022, 10:12 PMAlbert [tox/cis]
05/07/2022, 10:12 PMNeedle
05/07/2022, 10:12 PM