PromptFork

Supabase RLS: owner-write, public-read policies for a table

Generate correct, non-recursive RLS policies so anyone reads published rows and only owners edit their own.

Open in Studio
Prompt
You are a Postgres + Supabase security expert. For the table `[TABLE]` with an `owner_id uuid references auth.users` (or `profiles(id)`) and a `status text` column, write Row Level Security policies.

Requirements:
- Enable RLS on the table.
- SELECT: anyone (anon + authenticated) can read rows where `status = 'published'`; owners can read all of their own rows.
- INSERT: authenticated users only, and only with `owner_id = auth.uid()`.
- UPDATE/DELETE: only the owner (`owner_id = auth.uid()`), both `using` and `with check`.
- Make every statement idempotent with `drop policy if exists` before `create policy`.
- Note explicitly which operations the service role still performs (it bypasses RLS).

Return one SQL block, then a short bullet list explaining what each policy allows and the one mistake people make (recursive policies / forgetting `with check`).
Source
promptfork seed
License
CC-BY-4.0
Published
6/23/2026

More prompts you might like

Next.js 15 App Router page with streaming, caching, and server data

Scaffold a production App Router page: Server Component data fetching, Suspense streaming for instant TTFB, correct cache strategy (fetch cache vs unstable_cache vs revalidatePath), loading/error boundaries, and generateMetadata — with the non-obvious patterns most tutorials skip.

New

Tailwind analytics dashboard with animated stat cards, dark mode, and skeleton loading

Production-grade dashboard layout: KPI cards with counting animations and trend sparklines, a chart area, activity table — all with dark mode, skeleton loading states, and responsive breakpoints defined to the pixel.

New

Stripe webhook handler with signature verify + idempotency

Production-ready Stripe webhook route that verifies the signature and processes events exactly once.

New

.cursorrules for a strict TypeScript + React codebase

A tuned .cursorrules file that keeps Cursor's agent on-convention: strict types, no dead code, match existing patterns.

New

Refactor a React component into clean custom hooks

Extract stateful logic from a bloated component into typed, testable custom hooks.

New

Diagnose and fix a slow SQL query using EXPLAIN ANALYZE like a DBA

Paste a slow query and get a root-cause diagnosis, targeted index/rewrite fixes, and a before/after query plan — with specific pattern detection for N+1s, implicit casts, and composite index gaps.

New