42501 - "New row violates row-level security for table"
Hi there,
I'm a total noob. I started my coding journey with HTML in June, and have worked my way to Next.js. So, my apologies if I use the wrong terminology, get things wrong, or am generally confused.
I recently started building my first full-stack app. It uses Next.js 14 with the App router and Supabase. I used this quickstart framework to start: https://supabase.com/docs/guides/getting-started/quickstarts/nextjs. It came with a pre-made login page, and a folder name "/utils/supabase" that has two createClient components (client and server), as well as a middleware component. Attaching a screenshot of all three.
The project is pretty simple. The main parts, I think relevant to this, are:
The brief page is returns a React Hook Form (validated with zod) that lets users create a marketing brief. I'm able to login, navigate to the form, and fill it out. But when I submit it, I get a console error with the code 42501 that says "New row violates row-level security for table". Screenshot attached. The page component is marked with 'use client' because I'm using useState to dynamically update the price on the form.
When a user submits a, I want it to be added to the briefs table in a way only they can query.
In Supabase, I only have one table (briefs). It only has one RLS policy, currently. Screenshot attached. I tried temporarily disabling RLS to test in in development. That let me insert data into the table, no problem.
I've been struggling with this all day, and I'm very lost. I realize Next.js 14 is very new (which I didn't know when I started learning it 2 weeks ago), and there isn't a lot of info out there on this particular issue. At least not that I'm currently able to understand.
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.