SupabaseS
Supabase3y ago
Nils

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:

/app
/login
/dashboard
/brief/page. → GitHub: https://github.com/NilsWestgardh/briefbuddy/blob/main/app/dashboard/brief/page.tsx
/utils
/supabase
/server.ts
/client.ts
/middleware.ts

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.

I would greatly appreciate any and all help!

Nils
Screenshot_2023-12-08_at_17.57.47.png
Screenshot_2023-12-08_at_17.53.12.png
Screenshot_2023-12-08_at_17.37.36.png
GitHub
BriefBuddy helps you go from marketing brief to campaign ideas in minutes, not days. - NilsWestgardh/briefbuddy
Was this page helpful?