Home / Guides / Cursor rules for Next.js + Supabase
Cursor rules for Next.js + Supabase
Short answer: Cursor rules for Next.js + Supabase are small .mdc files in .cursor/rules/ that stop AI agents from the expensive mistakes: tables without RLS (or turning RLS off "to fix it"), trusting getSession() on the server instead of getUser(), scattering Supabase clients, unlocking paid access from the Stripe success redirect instead of a verified webhook, and prefixing secrets with NEXT_PUBLIC_. Put a scoped RLS rule on supabase/** first; the free one below is enough to start.
--- description: Migrations and row-level security globs: supabase/** alwaysApply: false --- - For each newly created table, enable row level security and define its policies in the same migration. - Policies use (select auth.uid()) for performance; separate policies per command (select/insert/update/delete). - Add indexes on every column used in a policy or foreign key. - Never disable RLS to 'make it work'. If a query fails, fix the policy and explain it. - Regenerate types after schema changes with `supabase gen types typescript --local`, writing to the project's existing types file (create its folder first if it doesn't exist).
Agents get the same few things wrong in a Next.js + Supabase app, and those mistakes are the expensive ones:
- Creating tables without row-level security, or switching RLS off "to fix the error".
- Trusting
getSession()on the server instead ofgetUser(), which re-validates the token. - Creating Supabase clients all over the place instead of one server helper and one browser helper with
@supabase/ssr. - Granting paid access from the Stripe success redirect instead of a verified webhook.
- Prefixing secrets with
NEXT_PUBLIC_, which ships them to every browser.
How Cursor rules work
Put .mdc files in .cursor/rules/. The front matter decides when a rule loads: alwaysApply: true for core rules, or globs so a rule loads only when matching files are in context. Keep each rule small and scoped. One giant rules file gets skimmed and ignored. For Codex, Claude Code and other tools, mirror the core rules in AGENTS.md.
A layout that works
00-core (always on), 20-supabase-auth (globs: lib/supabase/**, middleware.ts), 30-database-rls (supabase/**), 40-stripe (app/api/stripe/**), 50-env-secrets (.env*, lib/env.ts). The RLS rule above is the one that saves you the most money. A Supabase MCP server connection can show the agent the current tables; keep it on read_only=true so it inspects instead of migrating.
Building on Next.js + Supabase?
The Supabase + Next.js Agent Kit (DRW-06, $19) is the full version of these rules for this stack: AGENTS.md + CLAUDE.md, 8 scoped Cursor rules (@supabase/ssr auth, RLS in every migration, typed queries, secret key, Edge Functions, Stripe webhooks), a Claude Code hook that blocks a new table without RLS, a read-only migration-reviewer subagent and 10 prompts.
Written against documented conventions as of October 2026; not yet run against a reference project. 14-day refund.
Want the general pack instead?
Still deciding between free lists and paid marketplaces? Read where to buy Cursor rules first.
The Vibe Starter Rules Pack ($19) adds AGENTS.md, CLAUDE.md, 8 scoped rules (auth, Stripe webhooks, env, tests, UI), 12 slash-command prompts and launch checklists.
Not ready for a full pack? Start with One-File Agent Rules ($9), one universal AGENTS.md for any stack, or download the free Starter AGENTS.md (no email needed).
14-day refund, no questions.