nextjs15-supabase-cursorrules — правило для Cursor: 27 архитектурных
Правило для Cursor, которое держит агента в рамках стека Next.js 15, Supabase и TypeScript strict — от проверки сессии до RLS и ключей Stripe.
.cursor/rules/nextjs15-supabase-cursorrules-prompt-file.mdcЧто делает nextjs15-supabase-cursorrules-prompt-file
Файл описывает 27 правил для проекта на Next.js 15 (App Router) с React 19, Supabase, Tailwind CSS и shadcn/ui. Агент читает их перед генерацией кода и не должен отклоняться: в тексте прямо сказано следовать всем правилам безусловно.
Среди запретов — вызов getSession() на сервере вместо getUser(), синхронный доступ к params и searchParams, импорт из устаревшего @supabase/auth-helpers-nextjs, таблицы без RLS, ключи Stripe с префиксом sk_ в переменных NEXT_PUBLIC_, тип any и проверка авторизации в middleware. Для мутаций правило требует Server Actions с валидацией через Zod и ответом ActionResponse<T>, а каждая страница с загрузкой данных должна иметь соседние loading.tsx и error.tsx.
В файле приведены примеры кода: правильный и неправильный вариант для каждого из десяти разобранных правил. Полный набор из 27 правил лежит отдельно, в репозитории vibestackdev/vibe-stack, и ставится командой npx vibe-stack-rules init. Если ваш проект не на Supabase или вы уже перешли на другой слой авторизации, часть запретов будет спорить с текущим кодом — это повод проверить, какие правила вообще применимы.
Какие задачи решает
- поймать вызов
getSession()на сервере до того, как он уедет в прод - не забыть
awaitуparamsиsearchParamsв Next.js 15 - включить RLS на каждой таблице Supabase
- убрать
anyиз кода и оставить TypeScript strict - не вынести
sk_-ключ Stripe вNEXT_PUBLIC_
Примеры запросов агенту
- Добавь страницу товара: возьми
idизparamsчерезawaitи загрузи запись из Supabase. - Сделай Server Action для создания записи с валидацией Zod и проверкой пользователя через
getUser(). - Проверь мой код на нарушения правил Next.js 15 и Supabase из этого файла.
Как установить nextjs15-supabase-cursorrules-prompt-file
Вручную: положить файлы
.cursor/rules/nextjs15-supabase-cursorrules-prompt-file.mdcВо frontmatter: description, globs, alwaysApply
Вручную: положить файлы
.claude/rules/nextjs15-supabase-cursorrules-prompt-file.mdПоле paths во frontmatter ограничивает файлы: globs из источника → paths
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.github/instructions/nextjs15-supabase-cursorrules-prompt-file.instructions.mdПоле applyTo задаёт, к каким файлам применять: globs из источника → applyTo
Вручную: положить файлы
.devin/rules/nextjs15-supabase-cursorrules-prompt-file.mdВручную: положить файлы
.clinerules/nextjs15-supabase-cursorrules-prompt-file.mdПо шагам, с командами для каждой платформы: Cursor rules: файлы .mdc, четыре режима и замена .cursorrules
Из того же набора68
Похожие
Рядом в теме «Безопасность»
Всё по теме «Безопасность» →Вопросы о nextjs15-supabase-cursorrules-prompt-file
Как установить nextjs15-supabase-cursorrules в Cursor?
Положите файл по пути .cursor/rules/nextjs15-supabase-cursorrules-prompt-file.mdc в корне проекта. Cursor подхватит его как правило.
Что делает это правило?
Задаёт агенту 27 архитектурных ограничений для стека Next.js 15, Supabase и TypeScript strict: проверка сессии, асинхронные params, RLS, Server Actions, ключи Stripe.
Где взять полный набор из 27 правил?
В файле указан репозиторий vibestackdev/vibe-stack и команда npx vibe-stack-rules init для быстрой установки.
Исходный текст
nextjs15-supabase-cursorrules-prompt-file.mdc · CC0-1.0
---
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.
```typescript
// ✅ 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.
```typescript
// ✅ 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.
```typescript
// ✅ 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.
```sql
-- ✅ 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<T>.
```typescript
'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
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules