TraceResolveSRE Platform
MCP ServerAdmin
Back to CatalogSupabase / PostgreSQL

Supabase: new row violates row-level security policy for table (42501)

PostgrestError: new row violates row-level security policy for table "documents" (code 42501)
Immediate Remediation
sql
-- In Supabase SQL Editor: Add an INSERT and SELECT policy for authenticated users:
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Users can insert own documents"
ON documents FOR INSERT
TO authenticated
WITH CHECK (auth.uid() = user_id);

CREATE POLICY "Users can read own documents"
ON documents FOR SELECT
TO authenticated
USING (auth.uid() = user_id);
Root Cause Analysis

Row Level Security (RLS) is enabled on the table, but no active policy permits the current user role (anon or authenticated) to execute the INSERT/UPDATE operation.

Verification & Guardrails

  • Verify that auth.uid() matches the user_id column type (UUID vs text).
  • Service role client keys bypass RLS, but should NEVER be exposed in public client bundles.

Have a custom or uncategorized crash?

Run your trace through our in-memory client privacy sandbox for instant SRE remediation.

Open Diagnostic Studio