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.

.cursor/rules/30-database-rls.mdc
---
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:

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.

FREE · 1 FILE · WORKS IN EVERY AGENT

Get the free Starter AGENTS.md

A 40-line rules file that makes Cursor, Claude Code, Codex and Windsurf plan first, keep diffs small and run your tests before saying "done". We email it to you instantly, plus one follow-up and a short note when a new pack ships. Unsubscribe anytime. Privacy