supabase-rls-and-auth
Skill10 starsChanged 6 months agoMITView on GitHub
Use when creating Supabase tables, row level security policies, multi-tenant data isolation, auth-gated routes, or fixing users seeing wrong data. Not for styling, forms validation only, or non-Supabase auth providers unless wiring sessions to Supabase.
In this repository56 other files it gives its agents.
- accessibility-passSkill
- analytics-eventsSkill
- api-error-handlingSkill
- audit-logging-backendSkill
- background-jobs-and-cronSkill
- dark-mode-and-themingSkill
- dashboard-charts-rechartsSkill
- edge-functions-and-webhooksSkill
- email-and-notificationsSkill
- error-states-and-empty-uiSkill
- feature-flags-and-togglesSkill
- file-upload-storageSkill
- i18n-multi-languageSkill
- lovable-prompting-playbookSkill
- lovable-ship-checklistSkill
- migration-playbookSkill
- multi-tenant-backendSkill
- onboarding-copySkill
- optimistic-updatesSkill
- payment-failed-and-recoverySkill
- payment-webhook-idempotencySkill
- payment-webhook-testingSkill
- performance-budgetSkill
- pg-cron-recipesSkill
- pg-cron-scheduled-jobsSkill
- pg-cron-with-pg-net-edgeSkill
- postgres-full-text-searchSkill
- postgres-triggers-and-functionsSkill
- pricing-and-billingSkill
- programmatic-seo-content-qualitySkill
- programmatic-seo-pagesSkill
- rate-limiting-edgeSkill
- realtime-and-subscriptionsSkill
- refactor-safe-diffSkill
- release-notesSkill
- seo-core-web-vitalsSkill
- seo-landing-pageSkill
- seo-meta-tags-spaSkill
- seo-sitemap-generationSkill
- seo-ssr-and-prerenderingSkill
- seo-structured-dataSkill
- server-input-validationSkill
- shadcn-patternsSkill
- soft-delete-and-archivingSkill
- stripe-one-time-payment-webhooksSkill
- stripe-payment-webhooksSkill
- supabase-auth-flowsSkill
- supabase-database-designSkill
- support-replySkill
- tanstack-infinite-queriesSkill
- tanstack-mutations-and-invalidationSkill
- tanstack-prefetch-and-hydrationSkill
- tanstack-query-alternativeSkill
- tanstack-router-data-loadersSkill
- tanstack-start-server-routesSkill
- typed-api-hooks-formsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Every user-owned table must have RLS enabled and policies before shipping.
- Very specific: line 50
Use WITH CHECK on insert/update mirroring the same rule.
- Distinctive: line 54
Use Supabase Auth session.
- Very specific: line 55
Read auth.uid() in policies.
- Very specific: line 62
Use (select auth.uid()) inside policies (with the parentheses) so Postgres caches the value per statement instead of per row.
- Distinctive: line 74
Ask the user to test with two accounts: user A must not read/write user B's rows.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Supabase RLS and auth
For sign-in flows and OAuth, use supabase-auth-flows. This skill covers data access policies.
Every user-owned table must have RLS enabled and policies before shipping. Never rely on hiding UI alone.
New table checklist
ALTER TABLE ... ENABLE ROW LEVEL SECURITY;- Policy for
SELECT— users read only their rows (or org rows). - Policy for
INSERT—auth.uid()matchesuser_id(or membership check). - Policy for
UPDATE/DELETE— same ownership rule. user_id(ororganization_id) column with FK toauth.userswhere applicable.- Service-role key never in client code.
Policy patterns
Single-user ownership
CREATE POLICY "users_select_own" ON public.posts
FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY "users_insert_own" ON public.posts
FOR INSERT WITH CHECK (auth.uid() = user_id);Organization / tenant
CREATE POLICY "members_select" ON public.projects
FOR SELECT USING (
EXISTS (
SELECT 1 FROM public.memberships m
WHERE m.organization_id = projects.organization_id
AND m.user_id = auth.uid()
)
);Use WITH CHECK on insert/update mirroring the same rule.
Client auth
- Use Supabase Auth session; gate routes with session check + redirect to login.
- Read
auth.uid()in policies; do not trust client-sentuser_idwithoutWITH CHECK. - For profile rows, create profile on signup (trigger or edge function), keyed to
auth.users.id.
Performance
Wrap repeated subqueries in a security definer helper (e.g. is_org_member(org_id)) — see multi-tenant-backend. This avoids re-evaluating membership joins per row and prevents recursion when policies reference the same table they protect.
Use (select auth.uid()) inside policies (with the parentheses) so Postgres caches the value per statement instead of per row.
Avoid
- Tables without RLS in production.
USING (true)on user data tables.- Storing roles only in localStorage.
- Exposing service role in Vite
VITE_*env vars. - Bypassing RLS with the service role from the client.
Verify before done
Ask the user to test with two accounts: user A must not read/write user B's rows. Flag as "needs manual check" if you cannot run two sessions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

