Upsert not working with Row Level Security

I am trying to setup an upsert for authenticated users. I have setup two row level policies, one is the insert for authenticated users only, the other is an update for authenticated users only. Couldn't get the update for authenticated users only to work, so testing out RLS for anonymous users as well, and I'm still getting the error
"new row violates row-level security policy for table "record""
"new row violates row-level security policy for table "record""
when performing the update. Performing the insert works ok, but the update gives me the error. My code is
const { error } = await supabase.from("record").upsert(
[
{
masuk: 10,
keluar: 10,
stok: 100,
company_name: "Acme Inc",
alat_name: "MF 150",
},
],
{
onConflict: "masuk,keluar,stok,company_name,alat_name",
}
);
const { error } = await supabase.from("record").upsert(
[
{
masuk: 10,
keluar: 10,
stok: 100,
company_name: "Acme Inc",
alat_name: "MF 150",
},
],
{
onConflict: "masuk,keluar,stok,company_name,alat_name",
}
);
The RLS for Update is attached
No description
4 Replies
garyaustin
garyaustin2y ago
You also need to meet the select policy.
You say authenticate user but your policy has anon as the role which will only work for anon.
meg hidey
meg hideyOP2y ago
yes I set it at as anon just to test if it works w anon, it doesn't also, if I do a regular update on this table, it works just fine with the anon policy only with the update of upsert does it fail
garyaustin
garyaustin2y ago
All 3 policies (select, update,insert) have to be the same role.
meg hidey
meg hideyOP2y ago
oh ill try again with authenticated then

Did you find this page helpful?