tandyman
03/27/2022, 5:54 PMNeedle
03/27/2022, 5:54 PM/title
command!
We have solved your problem?
Click the button below to archive it.Scott P
03/27/2022, 5:59 PMis_admin
column to your public users table (if you have one), or adding that property to the metadata of the user.
Your RLS policies would then include an OR
statement where is_admin
.tandyman
03/27/2022, 6:01 PM(auth.uid() = agent_id) OR auth.is_admin)
Scott P
03/27/2022, 6:10 PMsql
((auth.uid() = agent_id) OR is_admin)
Brackets are importanttandyman
03/27/2022, 6:10 PMScott P
03/27/2022, 6:12 PMuser
on the start of the or check as it's going to look up the column in the table that the policy applies to.
Personal preference is to also use auth.uid()
over just uid()
. I don't think it'd make a difference, but it ensures it's looking in the correct schema.tandyman
03/27/2022, 6:12 PMuser.is_admin
, auth.is_admin
and is_admin
all fail. Sometimes it says doesn't exist, or missing a FROM in the policy.Scott P
03/27/2022, 6:17 PMis_admin
column onto a test project, and both the following allowed me to add the select policy:
sql
(is_admin OR (auth.uid() = id))
or
sql
((auth.uid() = id) OR is_admin)
id
is the column where my users ID is stored, but I don't see how calling it agent_id
would differtandyman
03/27/2022, 6:19 PMis_admin
doesn't existCREATE POLICY "only admins can access" ON public.client_profiles FOR SELECT USING (is_admin);
is_admin
needs to be in auth.users, rather than public.users?garyaustin
03/27/2022, 6:34 PMtandyman
03/27/2022, 6:34 PMgaryaustin
03/27/2022, 6:35 PMtandyman
03/27/2022, 6:35 PMgaryaustin
03/27/2022, 6:36 PMtandyman
03/27/2022, 6:38 PMgaryaustin
03/27/2022, 6:40 PMtandyman
03/27/2022, 6:40 PMgaryaustin
03/27/2022, 6:55 PMtandyman
03/27/2022, 7:03 PMgaryaustin
03/27/2022, 7:04 PMtandyman
03/27/2022, 7:05 PMgaryaustin
03/27/2022, 7:07 PMtandyman
03/27/2022, 7:07 PMgaryaustin
03/27/2022, 7:08 PMtandyman
03/27/2022, 7:08 PMgaryaustin
03/27/2022, 7:09 PMtandyman
03/27/2022, 7:09 PMgaryaustin
03/27/2022, 7:10 PMtandyman
03/27/2022, 7:10 PM