Reputation: 57
I'm testing the Supabase RLS policies and when I try to update a store with an authenticated user I got a 404 error.
But when I try to use insert it works, but the rule of policies is the same!!
Upvotes: 1
Views: 2836
Reputation: 17764
Each policy applies to one of the 4 possible database operations (Select, delete, update, insert) so you'll need to create a new policy for updating the table. Adding this here for my future self.
You can use the built-in roles to allow access for authenticated or anonymous users:
create policy "Public profiles are viewable only by authenticated users"
on profiles for select
to authenticated
using ( true );
create policy "Public profiles are viewable only by authenticated users"
on profiles for select
to anon
using ( true );
Or you can use the built-in auth variable to perform other checks:
alter policy "Users can update their own record"
on "public"."users"
to public
using (
(auth.uid() = id)
);
alter policy "Users can view data"
on "public"."items"
to public
using (
(auth.uid() IS NOT NULL)
);
alter policy "Users can view data"
on "public"."items"
to public
using (
(auth.role() = 'authenticated'::text)
);
Upvotes: 0
Reputation: 51
Insert policy only works for a new row. You would probably need to create a separate update policy for your table.
This specific discussion might point you to the right direction: https://github.com/supabase/supabase/discussions/3476
Upvotes: 1