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 PMtandyman
03/27/2022, 6:02 PM(auth.uid() = agent_id) OR auth.is_admin)tandyman
03/27/2022, 6:04 PMtandyman
03/27/2022, 6:10 PMScott 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 PMtandyman
03/27/2022, 6:13 PMtandyman
03/27/2022, 6:16 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)Scott P
03/27/2022, 6:18 PMid 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 PMtandyman
03/27/2022, 6:20 PMtandyman
03/27/2022, 6:22 PMtandyman
03/27/2022, 6:23 PMtandyman
03/27/2022, 6:29 PMtandyman
03/27/2022, 6:29 PMis_admin doesn't existtandyman
03/27/2022, 6:29 PMCREATE POLICY "only admins can access" ON public.client_profiles FOR SELECT USING (is_admin);tandyman
03/27/2022, 6:30 PMtandyman
03/27/2022, 6:33 PMis_admin needs to be in auth.users, rather than public.users?garyaustin
03/27/2022, 6:34 PMtandyman
03/27/2022, 6:34 PMtandyman
03/27/2022, 6:35 PMgaryaustin
03/27/2022, 6:35 PMtandyman
03/27/2022, 6:35 PMgaryaustin
03/27/2022, 6:36 PMtandyman
03/27/2022, 6:38 PMtandyman
03/27/2022, 6:38 PMtandyman
03/27/2022, 6:38 PMgaryaustin
03/27/2022, 6:40 PMtandyman
03/27/2022, 6:40 PMtandyman
03/27/2022, 6:41 PMtandyman
03/27/2022, 6:42 PMtandyman
03/27/2022, 6:49 PMtandyman
03/27/2022, 6:49 PMgaryaustin
03/27/2022, 6:55 PMgaryaustin
03/27/2022, 6:56 PMtandyman
03/27/2022, 7:03 PMtandyman
03/27/2022, 7:03 PMtandyman
03/27/2022, 7:04 PMgaryaustin
03/27/2022, 7:04 PMtandyman
03/27/2022, 7:05 PMtandyman
03/27/2022, 7:05 PMtandyman
03/27/2022, 7:06 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 PMtandyman
03/27/2022, 7:16 PMtandyman
03/27/2022, 8:42 PMtandyman
03/27/2022, 8:42 PM