← ClaudeAtlas

rls-policylisted

Use when creating or changing a Supabase table, view or storage bucket that the app reads from the client, or when writing, reviewing or testing row level security policies.
beingRealFrank/stackproof · ★ 0 · AI & Automation · score 72
Install: claude install-skill beingRealFrank/stackproof
# Row level security for Supabase tables ## Detect first ```bash find . -type d -path '*supabase/migrations' -not -path '*/node_modules/*' | head -3 grep -rn -i "enable row level security" --include=*.sql . 2>/dev/null | grep -v node_modules | head -5 grep -rn "auth.uid()" --include=*.sql . 2>/dev/null | grep -v node_modules | head -5 ls supabase/tests apps/*/supabase/tests 2>/dev/null | head grep -n "schemas" supabase/config.toml apps/*/supabase/config.toml 2>/dev/null | head -3 ``` Copy the style of the repo's existing policies (naming, which role clauses, helper functions such as an account-membership function). Follow the project's conventions over the defaults below. ## Rules 1. **Every table in an exposed schema (usually `public`) gets RLS in the same migration that creates it:** `alter table public.notes enable row level security;`. Without it, anyone with the anon key can read and write it. 2. **One policy per operation** (`select`, `insert`, `update`, `delete`), each `to authenticated` unless the data is truly public. `update` needs both `using` and `with check`; `insert` needs `with check`. 3. **Wrap the auth function in a select:** `(select auth.uid()) = user_id`. Supabase documents this form so Postgres evaluates it once per statement instead of per row. 4. **No `using (true)` on write policies**, and no `using (true)` on reads unless the table is meant to be public (say so in a comment). 5. **Index the columns the policy filters on** (for example `user_id`).