0

I am using Supabase's RLS to control which users can delete certain records in the database. The records are associated with files in a bucket that will get deleted too. I expect that if the Supabase delete request fails (i.e. because the RLS policy is violated), I will get an error, and skip the file deletion too... but it turns out that when a request violates RLS, it just returns a 200 Success code and makes no changes to the DB. But then my script has no exception to throw and the files get deleted anyway. Is there any way to get an error when the query fails so that I can skip deleting my files?

      // Delete the file entry from the database
      const { error: deleteError } = await supabase
        .from('files')
        .delete()
        .eq('id', fileId);

      if (deleteError) throw deleteError;

      console.log("Errs", deleterror);
      // Delete the object from R2
      await context.env.MY_BUCKET.delete(fileData.r2_object_name);

1 Answer 1

0

Row-level security makes it appear that the rows you are no allowed to delete aren't there. Here are some ideas:

  1. check the number of rows deleted and throw an error if it is 0

  2. don't use row-level security, but use a BEFORE DELETE trigger that checks the condition and throws an error

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.