Category: Supabase and databases

Supabase: new row Violates row-level security policy at INSERT

Read this guide in Polish

Trying to save a new record returns a row-level security policy error, although SELECT works. INSERT evaluates WITH CHECK condition for a new record, not the USING condition for reading.

How to determine the source of the error

Save values of owner id and auth.uid() for the user performing the insertion in a safe test environment.

Check that the table has FOR INSERT TO authenticated policy and that the client does not send an empty owner field.

What to do step by step

1. Prepare WITH CHECK to force the owner's correct connection to the current identity.

2 . Set the owner id on the server or through a secure identity-based default instead of trusting any client value.

How to check the score

A correct record can be added and an attempt to save it for another owner is still rejected.

What to do

Do not set WITH CHECK (true) just to silence a permission error.