Database & Data Models
Open
Example from the ReviewMyCodes team
Supabase insert fails with "new row violates row-level security policy"
Description
Signed-in users should be able to add notes, but every insert from my Next.js app fails. Selecting existing notes works.
— This is an example problem from the ReviewMyCodes team, showing how a good question looks. Real community questions appear alongside it.
Expected
A signed-in user can insert a note that belongs to them.
Actual
Error: new row violates row-level security policy for table "notes" (code 42501)
Steps to reproduce
- Sign in
- Submit the "New note" form
- Check the error returned by supabase.from("notes").insert(...)
Code
sql
alter table notes enable row level security;
create policy "read own notes" on notes
for select using (auth.uid() = user_id);
-- insert code in the app:
-- await supabase.from("notes").insert({ title, body });