Why aren't my form submissions saving to Supabase? ("new row violates row-level security policy")
Run a free check: FlowWatch signs up, logs in and runs a Stripe test checkout on your app, then scans for exposed keys. You get a shareable report. Run the free check at flowwatch.org
Your waitlist, contact or feedback form says "Thanks!", but the table in Supabase stays empty. Nobody sees an error. You only find out when you go looking for signups and there are none.
Two facts explain most of these cases:
- supabase-js doesn't throw on database errors. A call like
await supabase.from('waitlist').insert({ email })returns{ data, error }. If the generated code never checkserror, the form shows its success message whether or not the row was saved. - Row Level Security (RLS) blocks writes by default. When RLS is on and no policy allows an action, Postgres denies it. Tables created in the Supabase Table Editor have RLS turned on by default, and AI builders often enable it in their migrations too. That's the right default, but a public form needs a policy that lets visitors insert.
Step 1: Find the real error (2 minutes)
- Open your live site, open DevTools → Network, and submit the form.
- Click the request to
…supabase.co/rest/v1/<your_table>. - Read the status and the response body:
| What you see | What it means | Go to |
|---|---|---|
401 (or 403 when signed in), body says new row violates row-level security policy for table "…" (code 42501) | RLS is on and no INSERT policy allows this role | Step 2 |
RLS error even though you have an INSERT policy | The INSERT policy's WITH CHECK failed (for example auth.uid() = user_id on an anonymous request, or a user_id that doesn't match the signed-in user), or the code asks for the row back (.insert().select()) or uses .upsert() | Step 3 |
permission denied for table … | The role lacks table privileges (grants were changed) | Step 4 |
| No request to Supabase at all, or a request to the wrong host | Missing or wrong environment variables in the deployed build | Step 5 |
409 with duplicate key value (code 23505) | That email is already in the table (a unique constraint did its job) | Show a friendly "you're already on the list" |
201 Created | It saved. Check you're looking at the same Supabase project and table | Step 5 |
Then fix the code so it never hides this again:
const { error } = await supabase.from('waitlist').insert({ email });
if (error) {
console.error(error);
// show an error state instead of the success message
}Step 2: Add an INSERT policy for visitors
Visitors who aren't logged in use the anon role. Give that role permission to insert, and nothing else:
create policy "Anyone can join the waitlist"
on public.waitlist
for insert
to anon, authenticated
with check ( true );You can make the check stricter, for example with check ( email is not null and char_length(email) <= 320 ). If the form is for signed-in users only, use to authenticated and tie rows to the user, for example with check ( (select auth.uid()) = user_id ).
Don't fix this by turning RLS off or by adding a select policy for anon with using (true). On a waitlist, turning RLS off while anon still has SELECT, or a using (true) policy, lets anyone with your public anon key read every email address in the table. A narrower SELECT policy would not expose every address.
Step 3: An INSERT policy is there, but it still fails
An existing INSERT policy still raises this same 42501 error when its WITH CHECK returns false or null. auth.uid() = user_id fails on an anonymous request, and it fails when the signed-in user's id doesn't match user_id.
Postgres also checks more than the INSERT policy in two common cases:
- You ask for the inserted row back.
.insert(...).select()makes Postgres return the new row, and returned rows must pass aSELECTpolicy. If none allows it, Postgres throws an error instead of quietly returning nothing. For a public form you usually don't need the row back, so drop.select(). (Without it, supabase-js v2 returns no data from an insert.) - You use
.upsert(). An upsert isINSERT … ON CONFLICT DO UPDATE, which also needsSELECTandUPDATEpermission on the row. For an anonymous form, a plaininsertplus a unique constraint onemailis simpler and safer: duplicates come back as409and you show "already on the list".
These rules are in the Postgres CREATE POLICY docs (the "Policies Applied by Command Type" table).
Step 4: "permission denied for table"
This is a privilege problem, not a policy problem. permission denied for table means a grant is missing or was revoked. Many Supabase projects grant the anon and authenticated roles access to tables in public, and RLS policies then narrow it down, but not every project applies those grants automatically. If a migration revoked them, policies alone won't help. Restore the grant for the action you need (for example grant insert on public.waitlist to anon;) and keep RLS on. A schema that isn't exposed to the API usually fails earlier, with a missing-schema or missing-relation error.
Step 5: Works locally, not on Vercel or Netlify
If no request reaches Supabase in production, or it goes to another project:
- Check the variable names your framework exposes to the browser. Vite only exposes variables prefixed
VITE_(for exampleVITE_SUPABASE_URL). Next.js only exposesNEXT_PUBLIC_ones. A variable without the right prefix isundefinedin the browser. - Redeploy after adding or changing variables. These values are baked in at build time, and changes on Vercel apply to new deployments, not the one already live.
- Compare the host in the request (
<project-ref>.supabase.co) with the project you're looking at in the dashboard. Previews and production sometimes point at different projects.
Step 6: Re-test like a stranger
- Open the live site in a private window (logged out).
- Submit the form with a new email address.
- Confirm the request returns
201and the row appears in the table. - Submit the same email again and confirm you see your "already on the list" message, not a fake success.
An open insert endpoint can also attract spam. A unique constraint on email, a length check in the policy and a captcha on the form go a long way.
Catch silent failures early
Forms, signups and checkouts that fail quietly look fine from the founder's own account. FlowWatch runs signup, login and a Stripe test checkout on your live app on a schedule and emails you when a step breaks. Start with the free check at flowwatch.org.
Sources: PostgreSQL docs, CREATE POLICY (default deny; RETURNING and ON CONFLICT require SELECT policies; Table 301); PostgREST docs, Errors (42501 → 401 if anonymous, 403 if authenticated; 23505 → 409); Supabase docs, Row Level Security; Vite and Next.js docs on client-exposed environment variables; Vercel docs on environment variables applying to new deployments.
Questions: hello@flowwatch.org