Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
Updated · Applies to: Supabase, Lovable, Bolt, Cursor, v0, Vercel, Stripe
TL;DR fix: supabase-js does not throw on a failed insert: it returns { data, error }, and if the code never reads error the UI shows success anyway. Log the error first. It is almost always one of these: RLS is on with no INSERT policy for anon/authenticated (42501); the code chains .insert().select() or upserts and there is no SELECT policy (also 42501, and the row is rolled back); a Stripe webhook uses the anon/publishable key server-side so RLS blocks the write while the handler still returns 200; or production env vars point at a different Supabase project or branch. Use the secret/service_role key only on the server, check error, and return a 500 so Stripe retries.
Steps
- Log the error the UI is hiding. Change const { data } = await supabase.from('table').insert(row) to const { data, error } = await ...; if (error) { console.error(error); show the failure }. The error code and message tell you which cause below you have.
- Confirm the app talks to the project you're looking at. Log new URL(SUPABASE_URL).host in production and compare the project ref with the one in your Supabase dashboard URL. Vercel, Netlify and preview branches often have different values than .env.local.
- Run the 2-minute policy check. Run the check query in the SQL Editor. Any table your app writes to with rls_enabled = true and insert_policies = NONE rejects every insert from the browser with 42501.
- Add the missing INSERT (and, if needed, SELECT) policy. Add an INSERT policy with WITH CHECK for the role that writes (for example (select auth.uid()) = user_id). If the code uses .insert().select() or upsert, also add a SELECT policy scoped to the owner, or drop .select() for anonymous forms.
- Fix server-side writes (Stripe and other webhooks). Create the Supabase client in the webhook with the secret or service_role key from a server-only env var (never VITE_ or NEXT_PUBLIC_), check the insert error, and return 500 on failure so Stripe retries. Return 2xx only after the write succeeded.
- Check you're looking at the right table. Confirm schema (public vs another), table name, and that the Table Editor has no filter or sort hiding the new row. Run select * from public.your_table order by created_at desc limit 5 in the SQL Editor.
- Retest as a real user and with a real webhook. Submit the form signed out and signed in, then resend a Stripe test event from the dashboard or with stripe trigger, and confirm the row appears and the delivery shows a 2xx only when the row was written.
The bug: success on screen, nothing in the table
This one shows up in Lovable, Bolt and Cursor apps all the time. A contact form says “Thanks!”, a todo shows up in the list, a customer pays, and the Supabase table is empty. Or the Stripe dashboard shows your webhook answering 200 OK while the subscriptions row never appears.
The root is almost always the same line:
// What AI-generated code often looks like
await supabase.from('leads').insert({ email })
toast.success('Saved!')
supabase-js doesn’t throw when the database rejects a write. It resolves with { data, error } (the docs offer throwOnError() if you want a thrown error instead). If nobody reads error, every failure looks like success. Then the question is just which error, and there are only a handful.
Step 1: the 2-minute check
1. Make the app tell you the truth. Replace the insert with this and submit the form once:
const { data, error, status } = await supabase
.from('leads')
.insert({ email })
console.log('supabase host:', new URL(import.meta.env.VITE_SUPABASE_URL).host) // Next.js: process.env.NEXT_PUBLIC_SUPABASE_URL
console.log('insert status:', status, 'error:', error)
if (error) {
toast.error('Could not save, please try again.')
return
}
toast.success('Saved!')
2. Run this in the Supabase SQL Editor. It lists every table in public with RLS status, whether anon and authenticated have the INSERT grant, and their INSERT and SELECT policies:
select n.nspname as schema, c.relname as table_name,
c.relrowsecurity as rls_enabled,
has_table_privilege('anon', c.oid, 'INSERT') as anon_can_insert,
has_table_privilege('authenticated', c.oid, 'INSERT') as auth_can_insert,
coalesce((select string_agg(p.policyname || ' [' || array_to_string(p.roles, ',')
|| '] check ' || coalesce(p.with_check, p.qual, '-'), '; ')
from pg_policies p
where p.schemaname = n.nspname and p.tablename = c.relname
and p.cmd in ('INSERT', 'ALL')), 'NONE') as insert_policies,
coalesce((select string_agg(p.policyname || ' [' || array_to_string(p.roles, ',')
|| '] using ' || coalesce(p.qual, '-'), '; ')
from pg_policies p
where p.schemaname = n.nspname and p.tablename = c.relname
and p.cmd in ('SELECT', 'ALL')), 'NONE') as select_policies
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where c.relkind in ('r', 'p') and n.nspname = 'public'
order by 1, 2;
3. Match what you see:
| What you see | Cause | Fix |
|---|---|---|
42501 new row violates row-level security policy, and insert_policies = NONE | RLS on, no INSERT policy for this role | Cause 1 |
Same 42501, an INSERT policy exists, code uses .insert().select() or .upsert(), select_policies = NONE | Returning the row needs a SELECT policy | Cause 2 |
permission denied for table ... (42501), anon_can_insert = false | Missing grant, not a policy | Permission denied on new tables |
error: null, but the host isn’t your project’s ref | Wrong project or branch | Cause 3 |
Webhook shows 200 in Stripe, subscriptions empty | Anon key on the server, unchecked error | Cause 4 |
error: null, right host, row “missing” | Wrong schema, table or a Table Editor filter | Cause 5 |
Cause 1: RLS is on and there is no INSERT policy
With RLS enabled and no policy for the operation, Postgres denies it. For inserts the error is new row violates row-level security policy for table "leads" (code 42501). We have a full page on this error: Fix “new row violates row-level security policy for table”. The short version:
-- Signed-in users create their own rows
create policy "insert own todos" on public.todos
for insert to authenticated
with check ((select auth.uid()) = user_id);
-- A public contact/waitlist form: anyone may insert, nobody may read
create policy "anyone can submit a lead" on public.leads
for insert to anon, authenticated
with check (char_length(email) between 3 and 320);
Don’t “fix” it by disabling RLS or adding with check (true) on tables users shouldn’t write freely. See USING (true) policies.
Cause 2: .insert().select() or upsert with no SELECT policy
This one confuses people because the INSERT policy is there and the error message is identical. By default insert() doesn’t return the row; chaining .select() makes it an INSERT ... RETURNING. Postgres’s CREATE POLICY docs say that a RETURNING clause requires SELECT permission, and if the new row doesn’t pass a SELECT policy, an error is thrown. The same goes for INSERT ... ON CONFLICT with a conflict target, which is what upserts use. The whole statement fails and the row is rolled back.
Two fixes, depending on the table:
-- Owner data: let users read their own rows (you probably want this anyway)
create policy "read own todos" on public.todos
for select to authenticated
using ((select auth.uid()) = user_id);
// Anonymous forms (leads, waitlist, feedback): DON'T add an anon SELECT policy,
// that would let anyone read every submission. Just don't ask for the row back.
const { error } = await supabase.from('leads').insert({ email }) // no .select()
Cause 3: production points at a different project
error is null, the insert really succeeded, just not in the project you’re looking at. Common ways this happens:
- Vercel/Netlify env vars differ from
.env.local.VITE_andNEXT_PUBLIC_values are inlined into the JavaScript at build time (Vite and Next.js docs). Vercel says env var changes only apply to new deployments, so after fixing the Production values you have to redeploy. - Preview vs Production scope. Vercel scopes variables per environment; a preview deployment can read different values from production.
- Supabase branches. Supabase’s docs say each branch is a separate environment with its own instance and API credentials. A preview deployment wired to a branch writes to the branch’s database.
- An old project. Lovable, Bolt or a template created a second project and the app still points at it.
Check: the supabase host line from Step 1 is https://<project-ref>.supabase.co. Compare <project-ref> with the one in your dashboard URL (supabase.com/dashboard/project/<project-ref>).
Cause 4: a webhook writes with the anon key and returns 200 anyway
This is the expensive one: a customer pays, Stripe calls your webhook, the handler creates its Supabase client with the same anon or publishable key as the frontend, RLS blocks the write (42501, since you correctly have no anon INSERT policy on subscriptions), the handler ignores error, and returns 200. Stripe marks the event delivered and never retries.
The fix has three parts: server-only secret key, verified signature, and a non-2xx on failure.
// app/api/stripe/webhook/route.ts (Next.js App Router; same idea for an Edge Function)
import Stripe from 'stripe'
import { createClient } from '@supabase/supabase-js'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
// Server-only env vars. NEVER VITE_ or NEXT_PUBLIC_ (those ship to the browser).
const admin = createClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY!, // or the legacy SUPABASE_SERVICE_ROLE_KEY
{ auth: { persistSession: false, autoRefreshToken: false } }
)
export async function POST(req: Request) {
let event: Stripe.Event
try {
event = stripe.webhooks.constructEvent(
await req.text(), req.headers.get('stripe-signature')!, process.env.STRIPE_WEBHOOK_SECRET!
)
} catch {
return new Response('Bad signature', { status: 400 })
}
if (event.type === 'checkout.session.completed') {
const s = event.data.object as Stripe.Checkout.Session
const { error } = await admin.from('subscriptions').upsert(
{ stripe_customer_id: s.customer as string, user_id: s.client_reference_id, status: 'active' },
{ onConflict: 'stripe_customer_id' } // idempotent: Stripe can deliver the same event twice
)
if (error) {
console.error('subscriptions upsert failed', event.id, error)
return new Response('DB write failed', { status: 500 }) // non-2xx: Stripe retries
}
}
return new Response('ok', { status: 200 })
}
What Stripe’s docs say (fetched today):
- Stripe retries deliveries that didn’t get a
2xx: in live mode for up to three days with exponential back-off; in a sandbox three times over a few hours. - Endpoints can receive the same event more than once, so make the write idempotent (upsert on a Stripe ID, or log processed event IDs).
- Return a
2xxquickly, before slow work that could time out. A single upsert is fine to do before responding. If you have slow work (emails, PDFs, other APIs), write the event to a table first, return200once that write succeeded, and process it in the background.
What Supabase’s docs say about the key: a secret key (or the legacy service_role key) bypasses every RLS policy, so it belongs only in server code and never in a browser, a shipped app or source control. Supabase also notes that a secret key bypasses RLS only when the request carries no user access token: if you forward the user’s Authorization header to that client, it runs under the user’s policies again. Keep the webhook client separate from any per-user client. And don’t reuse the webhook’s admin client in routes that serve signed-in users: there it skips every policy and hands out other users’ rows. See RLS not working on the server: the service_role key.
If the webhook never gets past the signature check, that’s a different bug: Stripe “No signatures found matching the expected signature”. To recover events Stripe already marked delivered, list them in the Dashboard or API and replay them through the fixed handler (see Stripe’s “Process undelivered webhook events”).
Cause 5: the row is there, you’re looking in the wrong place
Small, but it happens (the first three are from our own rescue work, not from a doc; the trigger case we reproduced):
- Wrong schema. The client was created with
db: { schema: 'api' }or the code calls.schema('...'), and you’re looking atpublic. - Similar table names.
leadvsleads,Profilesvsprofiles(quoted identifiers are case-sensitive in Postgres). - Table Editor filters and sorting. A saved filter or a sort on another column hides the newest row; the grid can also show a page that predates the insert.
- Trigger or rule side effects. A
BEFORE INSERTtrigger returningNULLsilently skips the row with no error. - Your app only reads the first 1,000 rows. The insert worked, but the list page does a plain
.select()and Supabase’s Data API returns at most 1,000 rows per request by default, with no error, so rows past that never show. See Supabase only returns 1,000 rows.
Check directly in the SQL Editor:
select * from public.leads order by created_at desc limit 5;
Paste this into Lovable, Bolt or Cursor
Rows are not being saved to Supabase even though the app shows success
(and/or the Stripe webhook returns 200 without writing). Fix it without
disabling RLS:
1. Find every supabase .insert(), .upsert() and .update() call. Destructure
{ data, error }, log error, show a failure message when error is set, and
only show success when error is null.
2. Run this check and show me the result: for each table in public, RLS status,
INSERT grants for anon/authenticated, and INSERT/SELECT policies from pg_policies.
3. For each table the app writes to with no INSERT policy, propose one with
WITH CHECK scoped to the owner ((select auth.uid()) = user_id). For public
forms (leads, waitlist), allow insert only, no anon SELECT.
4. If code chains .select() after insert or uses upsert, either add an
owner-scoped SELECT policy or remove .select() for anonymous forms.
5. In every webhook/server route (Stripe etc.): create the Supabase client with
the secret/service_role key from a server-only env var (never VITE_ or
NEXT_PUBLIC_), verify the Stripe signature, check the insert error, return
500 on failure so Stripe retries, and make the write idempotent (upsert on
the Stripe customer/subscription id).
6. Print the Supabase host the production build uses and tell me which env
vars to set in Vercel/Netlify for Production, then remind me to redeploy.
7. Show me all SQL before running it. Never use USING (true) or disable RLS.
What we verified
- Reproduced on Postgres 17 (PGlite) with Supabase-style
anon,authenticatedandservice_role(withbypassrls) roles and anauth.uid()stand-in: with RLS on and no policy, ananoninsert failed with42501 new row violates row-level security policy; after adding anINSERTpolicy the same insert succeeded;insert ... returning(what.insert().select()sends) andinsert ... on conflict (id) do nothingboth failed with the same42501when there was noSELECTpolicy, and the row was rolled back; a signed-in user’s insert of a row for another user was rejected byWITH CHECK; after adding an ownerSELECTpolicy, insert-with-returning worked. A “webhook” insert intosubscriptionsasanonwas blocked, and asservice_roleit succeeded. ABEFORE INSERTtrigger returningNULLmade an insert succeed with no error and no row. The check query listed the missing policies correctly. - Docs-based (fetched Nov 16, 2026): supabase-js returning
{ data, error }instead of throwing andinsert()not returning rows unless you chain.select()(Supabase JS reference), secret/service_role keys bypassing RLS only without a user token and never belonging inVITE_/NEXT_PUBLIC_(Supabase RLS and API keys docs), branch credentials (Supabase Branching), Stripe’s retry schedule, duplicate deliveries and quick-2xx guidance (Stripe webhooks docs), build-time inlining ofVITE_/NEXT_PUBLIC_(Vite, Next.js) and env changes applying only to new deployments (Vercel). - Not reproduced: we did not run supabase-js, PostgREST, a Stripe endpoint or a live Supabase project for this page. The Next.js webhook handler above is an example pattern, not tested code. The schema, table-name and Table Editor items in Cause 5 are from our own experience, not a doc.
Related: new row violates row-level security policy, permission denied on new tables (Oct 30, 2026), Stripe webhook signature errors, users updating their own plan column, Invalid API key after rotating Supabase keys, and Check your Supabase RLS in two minutes.
When to get help
Get help if paying customers already went through checkout without their subscription row being written, if your webhook handler mixes the user's session with a secret key, or if your AI tool keeps "fixing" missing rows by disabling RLS or adding USING (true) policies.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
Why does my Supabase insert say success but no row appears?
Because supabase-js returns errors instead of throwing them. const { data } = await supabase.from('leads').insert(row) resolves normally even when the insert failed; the failure is in the error field. If your code only checks that the await finished, the UI shows success. Read error, log it, and show it. The usual messages are 42501 "new row violates row-level security policy" (missing INSERT or SELECT policy), "permission denied for table" (missing grant), or a constraint error.
Why does .insert().select() fail when a plain .insert() works?
Chaining .select() asks Postgres to return the new row (INSERT ... RETURNING). Postgres then also applies your SELECT policies to that row, and if none allows it the whole statement fails with 42501 "new row violates row-level security policy" and the row is rolled back. Add a SELECT policy scoped to the owner, or, for anonymous forms like contact or waitlist forms, drop .select() rather than letting anon read the table. Upserts with an ON CONFLICT target need SELECT too.
Why does my Stripe webhook return 200 but not update Supabase?
Most often the handler creates its Supabase client with the anon or publishable key, so it runs as the anon role and RLS blocks the write, then returns 200 anyway because it never checked error. Use the secret key (or legacy service_role key) from a server-only env var in the webhook, check the insert error, and return a 500 if it failed. Stripe treats any non-2xx as a failed delivery and retries.
Is it safe to use the Supabase service_role or secret key in a Stripe webhook?
Yes, on the server only. Supabase docs say the secret key bypasses every RLS policy and must never go in a browser, a shipped app or source control, and that VITE_ or NEXT_PUBLIC_ prefixes make your bundler ship it. Keep it in a server-only variable like SUPABASE_SECRET_KEY, verify the Stripe signature before using it, and don't pass the user's access token to that client: Supabase notes a request carrying a user token runs under that user's RLS policies even with a secret key.
Should my webhook return 200 even if the database write failed?
No. Stripe retries deliveries that get a non-2xx response: in live mode for up to three days with exponential back-off, and in a sandbox three times over a few hours. If you return 200 after a failed write, Stripe marks the event delivered and the row is never written. Return 2xx after the write succeeds, make the write idempotent (upsert on the Stripe customer, subscription or event ID), and if the work is slow, store the event first and process it in the background.
Rows show up locally but not in production. Why?
Production is probably writing to a different Supabase project. VITE_ and NEXT_PUBLIC_ variables are baked into the JavaScript at build time, Vercel applies env var changes only to new deployments, and Supabase branches each have their own instance and API credentials. Log the Supabase host in production, compare the project ref with your dashboard, fix the Production env vars, and redeploy.
The insert works in the SQL Editor. Why not from my app?
The SQL Editor runs as a privileged role that bypasses RLS, so it proves nothing about your policies. Your app runs as anon (signed out) or authenticated (signed in). Test from the app, or in SQL with set role anon; / set role authenticated; plus a request.jwt.claim.sub value, inside a transaction you roll back.
Sources
- Supabase docs: Row Level Security (grants vs policies, INSERT WITH CHECK, bypassing RLS with a secret key)
- Supabase docs: JavaScript reference, insert() and throwOnError()
- Supabase docs: Understanding API keys (secret keys bypass RLS, never prefix with VITE_/NEXT_PUBLIC_)
- Supabase docs: Branching (each branch has its own instance and API credentials)
- PostgreSQL docs: CREATE POLICY (RETURNING and ON CONFLICT require SELECT policies)
- Stripe docs: Receive Stripe events in your webhook endpoint (2xx, automatic retries, duplicates)
- Stripe docs: Process undelivered webhook events
- Vercel docs: Environment variables (changes apply only to new deployments)
- Vite docs: Env variables and modes (VITE_ is exposed to the client)
- Next.js docs: Environment variables (NEXT_PUBLIC_ is inlined at build time)
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)