Peanut
08/26/2021, 9:28 AMSELECT getIsUserEditorOrAdmin(auth.firebase_uid()) = TRUE
> ?column?
> false
jason-lynx
08/26/2021, 9:28 AMjason-lynx
08/26/2021, 9:29 AMSELECT role = 'admin' OR role = 'editor' FROM userAdminMeta WHERE id = auth.firebase_uid()
what do you get?Peanut
08/26/2021, 9:29 AMSELECT auth.firebase_uid()
> firebase_uid
> null
Looks like an issuePeanut
08/26/2021, 9:30 AMPeanut
08/26/2021, 9:30 AMauth.uid()
also returns null
jason-lynx
08/26/2021, 9:30 AMPeanut
08/26/2021, 9:32 AMpostgres
not superuser?jason-lynx
08/26/2021, 9:33 AMPeanut
08/26/2021, 9:35 AMjason-lynx
08/26/2021, 9:40 AMPeanut
08/26/2021, 9:46 AMPeanut
08/26/2021, 9:46 AMkennethcassel
08/26/2021, 12:09 PMEmreCan
08/26/2021, 12:46 PMkyrelldixon
08/26/2021, 5:13 PMScott P
08/26/2021, 5:59 PMsql
(SELECT CASE WHEN (
SELECT COUNT(*) FROM my_table
WHERE my_table.user_id = auth.uid()
GROUP BY my_table.user_id
) <= 50
) THEN true ELSE false end)
replace my_table
with the name of the table you're adding the policy to, and user_id
with the name of the column that contains the user ID. 50
would be if you want them to be able to create up to 50 rows maximum in the table.Scott P
08/26/2021, 6:00 PMjon.m
08/26/2021, 8:10 PMScott P
08/26/2021, 8:22 PMjon.m
08/26/2021, 8:22 PMPeanut
08/26/2021, 11:38 PMPeanut
08/27/2021, 12:06 AM"message": "invalid input syntax for type uuid: \"jAdocMIsWmRJg5JomxDNdHjNGFJp\""
I am casting auth.uid()
to text:
CREATE FUNCTION public.getisusereditororadmin(id TEXT)
RETURNS BOOLEAN
AS $$
SELECT (SELECT role = 'admin' OR role = 'editor' FROM userAdminMeta WHERE id = $1) IS NOT NULL
$$ LANGUAGE sql;
CREATE POLICY "Users can update their own profile OR staff can update any profile."
ON public.users
FOR UPDATE USING (
auth.uid()::TEXT = users.id OR
public.getisusereditororadmin(auth.uid()::TEXT)
);
If I modify my policy to not cast to TEXT
I get an error: function public.getisusereditororadmin(uuid) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
silentworks
08/27/2021, 12:14 AMTEXT
cashing on the auth.uid
Peanut
08/27/2021, 12:23 AMPeanut
08/27/2021, 12:26 AMBEGIN;
SET LOCAL request.jwt.claim.sub = 'a user id';
SET LOCAL ROLE authenticated;
UPDATE PUBLIC.users SET username = 'My username' WHERE id = 'my user id';
COMMIT;
If I comment out SET LOCAL ROLE authenticated;
the query succeeds but when it is there, it failsPeanut
08/27/2021, 12:43 AMauthenticated
role complete write access to my tables? I have RLS policies for ALL tablesjason-lynx
08/27/2021, 1:08 AMjason-lynx
08/27/2021, 1:08 AMjason-lynx
08/27/2021, 1:09 AM