Rule
0 installs · 0 said it worked
Guard Next.js 15 + Supabase code against common auth and security mistakes
A rule set for Cursor or Claude Code that steers AI-written Next.js 15 and Supabase code away from insecure getSession use, synchronous params, deprecated auth helpers, missing RLS, and exposed Stripe keys.
People use this for
- nextjs supabase auth security rules
- supabase rls policy review
- nextjs 15 async params fix
- secure supabase server auth code
- stop ai generating insecure nextjs code
- Name
guard-nextjs-15-supabase-code-against-common-auth-and-security-m- Works with
- Cursor
- License
- CC0(as observed at the source)
- Version
- v1 · updated Nov 29, 2026
Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Use this rule
$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/guard-nextjs-15-supabase-code-against-common-auth-and-security-mistakes-t48m/export/mdc" -o .cursor/rules/guard-nextjs-15-supabase-code-against-common-auth-and-security-m.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save guard-nextjs-15-supabase-code-against-common-auth-and-security-m.mdc as .cursor/rules/guard-nextjs-15-supabase-code-against-common-auth-and-security-m.mdc for this project or ~/.cursor/rules/guard-nextjs-15-supabase-code-against-common-auth-and-security-m.mdc for every project, then start a new session.
Rule
description: "27 architecture rules preventing AI hallucinations: insecure auth (getSession vs getUser), synchronous params, deprecated imports, missing RLS, and Stripe key exposure. Built for Cursor Agent and Claude Code." globs: */ alwaysApply: false
Next.js 15 + Supabase Architecture Rules
You are an expert Next.js 15 developer working with Supabase, TypeScript (strict), and shadcn/ui. Follow ALL rules below unconditionally. If you are tempted to deviate, re-read the rule.
Tech Stack
- Framework: Next.js 15 (App Router) with React 19
- Language: TypeScript (strict mode)
- Styling: Tailwind CSS + shadcn/ui
- Database: Supabase (PostgreSQL + RLS)
- Auth: Supabase SSR (cookie-based, @supabase/ssr)
- Validation: Zod
- Payments: Stripe (server-side only)
RULE 1: NEVER use getSession() on the server
SECURITY CRITICAL. getSession() reads the JWT from cookies WITHOUT verifying it. A forged cookie passes silently. ALWAYS use getUser() for server-side auth.
// ✅ CORRECT — verified with Supabase auth server
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) redirect('/login')
// ❌ WRONG — reads JWT without verification, session can be forged
const { data: { session } } = await supabase.auth.getSession()
RULE 2: NEVER access params synchronously in Next.js 15
In Next.js 15, params and searchParams are Promises. Synchronous access compiles but crashes at runtime.
// ✅ CORRECT
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params
}
// ❌ WRONG — runtime crash
export default function Page({ params }: { params: { id: string } }) {
const { id } = params // TypeError at runtime
}
RULE 3: NEVER import from @supabase/auth-helpers-nextjs
This package is deprecated. It does NOT work with Next.js 15 App Router cookies. ALWAYS use @supabase/ssr with manual cookie handling.
// ✅ CORRECT
import { createServerClient } from '@supabase/ssr'
// ❌ WRONG — deprecated, broken with App Router
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'
RULE 4: All database tables MUST have RLS enabled
Every Supabase table must have Row Level Security enabled. Without RLS, any user with the anon key can read ALL data from the table.
-- ✅ Always add after CREATE TABLE:
ALTER TABLE public.my_table ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Users can only read their own data"
ON public.my_table FOR SELECT
USING (auth.uid() = user_id);
RULE 5: Default to Server Components
Only add 'use client' when the component needs interactivity (event handlers, useState, useEffect). Push 'use client' to the smallest leaf component possible.
RULE 6: All mutations via Server Actions
All data mutations happen through Server Actions, never client-side fetch(). Always validate with Zod, authenticate with getUser(), and return ActionResponse.
'use server'
import { z } from 'zod'
type ActionResponse<T = void> =
| { success: true; data: T }
| { success: false; error: string }
const Schema = z.object({ title: z.string().min(1).max(200) })
export async function createItem(input: unknown): Promise<ActionResponse> {
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) return { success: false, error: 'Unauthorized' }
const result = Schema.safeParse(input)
if (!result.success) return { success: false, error: 'Invalid input' }
const { error } = await supabase.from('items').insert({ ...result.data, user_id: user.id })
if (error) return { success: false, error: 'Failed to create item' }
revalidatePath('/items')
return { success: true, data: undefined }
}
RULE 7: Error boundaries for every data-fetching page
Every page that fetches data MUST have sibling loading.tsx and error.tsx files.
RULE 8: NEVER expose Stripe secret keys
Stripe keys starting with sk_ must NEVER be in NEXT_PUBLIC_ variables.
Use process.env.STRIPE_SECRET_KEY (server-only).
RULE 9: TypeScript strict mode, no any
NEVER use any. Use unknown with Zod validation or type narrowing.
tsconfig.json MUST have strict: true.
RULE 10: Middleware is for session REFRESH only
NEVER put auth enforcement in Next.js middleware. Middleware runs on Edge Runtime and cannot verify Supabase JWTs. Auth enforcement belongs in layouts/pages with getUser().
Full rule set (27 rules) available at: https://github.com/vibestackdev/vibe-stack Quick install: npx vibe-stack-rules init
No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.
Tried it
Reports from people who added this rule to their editor. They roll up into the badges above.
No one has filed a report yet. Try the prompt and be the first.
Related rules
- Claude api: reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming,…
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any fo
Coding · @anthropic
- Nginx config security review with fixes and checker script
Agent skill that reviews nginx configs for TLS, header, alias traversal, admin exposure and rate-limit problems, runs a stdlib checker, and returns a minimal route-preserving fixed config with reload and curl test steps.
Coding · @f
- Forensic PHP codebase security, performance and quality audit
A long checklist-driven prompt that has the model act as a senior PHP reviewer and audit a codebase for type safety, security holes, database and performance issues, code quality, architecture, dependencies, and testing gaps, then report findings by severity with a final scored summary.
Coding · @ersinkoc
- Cursor rules enforcing clean, readable, maintainable code practices
A Cursor .mdc rule file that guides the assistant toward clean code: named constants, meaningful names, sparing comments, single-purpose functions, DRY, language style standards, extracted conditionals, continuous refactoring, and version control.
Coding · @patrickjs
- Security guardrails that keep an AI email assistant from being hijacked by malicious messages
A full system prompt giving an AI assistant that reads or manages email a security mindset: treat email as untrusted data, require approval for outward actions, avoid leaking private data, and report phishing and injection attempts calmly.
Productivity · @thanos0000
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.