Supabase + Next.js Rules
Cursor rules for Supabase + Next.js App Router. Client separation, RLS, auth middleware, server actions for mutations.
What it does
Teaches Cursor the client/server separation Supabase requires: @supabase/ssr in server components and route handlers, @supabase/supabase-js only in client components, never the service_role key on the client, middleware.ts refreshing sessions on every request, and RLS enabled on every table with policies referencing auth.uid() and organization_id.
What it solves
Most Supabase + Next.js bugs come from mixing client and server Supabase clients or disabling RLS during development and forgetting to re-enable it. These rules prevent both classes of mistake.
How to install
Which tool are you using?
Not sure? Claude.ai is the website. Claude Code is the command-line tool you install separately. Cursor is a code editor that reads .cursorrules.
- 01
Copy the rules
Click the Copy button on the code block below to grab the full contents of .cursorrules.
- 02
Create .cursorrules at your project root
Cursor reads .cursorrules from the top-level folder of your project. Paste the copied content there.
terminalshelltouch .cursorrules - 03
Reload Cursor
Cmd+Shift+P → "Developer: Reload Window". Cursor picks up the new rules immediately.
- 04
Verify with a test prompt
Ask Cursor to generate a component or function in your stack. The output should follow the conventions in your rules file.
The cursor rules file
Copy the full contents below, or download the file directly.
# Supabase + Next.js Cursor Rules You are an expert building full-stack apps with Supabase + Next.js App Router. ## Client Separation- @supabase/ssr for server components and route handlers- @supabase/supabase-js for client components only- Never import service_role key on the client- One createClient util per context (server, client, middleware) ## Auth- Use middleware.ts to refresh sessions on every request- Protect routes by checking user in server components- Sign-in, sign-up, magic-link flows via Supabase auth- Never trust client-only auth state for authorization ## RLS- RLS enabled on every table — no exceptions- Policies reference auth.uid() and organization_id- Never disable RLS in prod to "just fix it"- Test policies with anon key in staging ## Data- Typed queries via supabase-js generics- Generate types with supabase gen types typescript- Server Actions for mutations, not client writes- Realtime subscriptions from client components only ## Storage- Signed URLs for private buckets- Public buckets only for truly public assets- Image transform + caching via Next.js ImageExample output
What Claude does before and after you install this cursor rules.
Cursor imports service_role in a client component, disables RLS to fix a query, and writes mutations from the client.
Cursor keeps service_role server-only, writes mutations as Server Actions, generates typed queries, and tests RLS policies before shipping.
Customization tips
For projects that use Supabase but not Next.js, remove the Next.js-specific middleware rule. For orgs without multi-tenancy, drop organization_id from the RLS section. If you use Drizzle with Supabase, add a Drizzle-specific section to replace supabase-js for reads.
Related resources
Next.js + TypeScript Rules
Cursor rules for Next.js 14 App Router + strict TypeScript. Server Components, Server Actions, Zod, Tailwind, shadcn/ui.
Next.js Full Stack Skill
App router patterns, server components, API routes, and Next.js 14+ conventions baked into every response.
Supabase MCP
MCP server that lets Claude run queries, inspect schema, and manage your Supabase project from chat.
Frequently asked questions
Does it work with Pages Router?
Partially. Middleware patterns differ; rewrite the Auth section.
Requires RLS?
Assumed on every table. The rules will not suggest disabling RLS.
Does it cover Supabase Edge Functions?
Not directly. Add an Edge Functions section if used.
Supports realtime?
Yes — the rules require realtime subscriptions from client components only.
Compatible with Clerk?
No — the auth rules assume Supabase Auth. Edit for other providers.
Want more like this?
Browse the full RohanKit library — free resources for Claude and Cursor.