prisma-better-auth-nextjs
Prisma 7 + Better Auth + Next.js App Router. Email/password, OAuth, 2FA, rate limiting, audit logging. Triggers: add auth, better auth, prisma auth, nextjs login, sign-up/sign-in, auth scaffold.
- License 许可
- Apache-2.0
- 最近更新
- 2026-08-29
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- prisma-better-auth-nextjs
- license
- Complete terms in LICENSE.txt
- description
- Prisma 7 + Better Auth + Next.js App Router. Email/password, OAuth, 2FA, rate limiting, audit logging. Triggers: add auth, better auth, prisma auth, nextjs login, sign-up/sign-in, auth scaffold.
02 资源文件 27
- 参考文档evals/eval-execution.json2.6 KB
- 参考文档evals/eval-setup-accuracy.json2.7 KB
- 许可证LICENSE.txt11.1 KB
- 参考文档references/1-setup-project/create-nextjs-app.md624 B
- 参考文档references/2-setup-prisma/configure-prisma.md1.0 KB
- 参考文档references/2-setup-prisma/generate-client.md815 B
- 参考文档references/2-setup-prisma/global-client.md1.2 KB
- 参考文档references/2-setup-prisma/install-dependencies.md950 B
- 参考文档references/2-setup-prisma/neon-adapter.md2.5 KB
- 参考文档references/2-setup-prisma/slow-query-logging.md2.0 KB
- 参考文档references/3-setup-better-auth/add-auth-models.md2.4 KB
- 参考文档references/3-setup-better-auth/email-verification.md2.5 KB
- 参考文档references/3-setup-better-auth/install-configure.md1.7 KB
- 参考文档references/3-setup-better-auth/migrate-database.md911 B
- 参考文档references/3-setup-better-auth/oauth-providers.md2.2 KB
- 参考文档references/3-setup-better-auth/session-config.md2.3 KB
- 参考文档references/3-setup-better-auth/two-factor.md1.9 KB
- 参考文档references/4-api-routes/audit-logging.md3.2 KB
- 参考文档references/4-api-routes/rate-limiting.md3.6 KB
- 参考文档references/4-api-routes/setup-routes.md1.4 KB
- 参考文档references/5-pages/dashboard.md1.6 KB
- 参考文档references/5-pages/home.md1.1 KB
- 参考文档references/5-pages/sign-in.md2.1 KB
- 参考文档references/5-pages/sign-up.md2.3 KB
- 参考文档references/6-test/test-app.md2.8 KB
- 脚本scripts/scaffold.py11.2 KB
- 脚本scripts/tests/test_scaffold.py4.7 KB
03 SKILL.md 正文
Prisma + Better Auth + Next.js Setup Guide
Source: prisma.io/docs/guides/authentication/better-auth/nextjs
Prerequisites
- Node.js 20+, Next.js App Router + TypeScript
- PostgreSQL (Neon, Supabase, local) — for MySQL/SQLite swap the adapter
Steps Overview — Core (Basic Setup)
| Step | Folder | Files | What |
|---|---|---|---|
| 1 | 1-setup-project/ |
create-nextjs-app | Create Next.js project |
| 2.1 | 2-setup-prisma/ |
install-dependencies | Install Prisma + pg |
| 2.2 | configure-prisma | prisma.config.ts |
|
| 2.3 | generate-client | Generate typed client | |
| 2.4 | global-client | Singleton src/lib/db/index.ts |
|
| 3.1 | 3-setup-better-auth/ |
install-configure | Install + src/lib/auth.ts |
| 3.2 | add-auth-models | User, Session, Account (with @@map) |
|
| 3.3 | migrate-database | Run migration | |
| 4.1 | 4-api-routes/ |
setup-routes | Catch-all + auth client |
| 5.1 | 5-pages/ |
sign-up | Sign up form |
| 5.2 | sign-in | Sign in form | |
| 5.3 | dashboard | Protected dashboard | |
| 5.4 | home | Landing page | |
| 6 | 6-test/ |
test-app | Test + troubleshoot |
Steps Overview — Advanced (Production-Grade)
| Step | Folder | Files | What |
|---|---|---|---|
| 2.5 | 2-setup-prisma/ |
neon-adapter | Neon serverless adapter + dual URLs |
| 2.6 | slow-query-logging | Structured slow query detection | |
| 3.4 | 3-setup-better-auth/ |
oauth-providers | Google + GitHub OAuth |
| 3.5 | two-factor | TOTP 2FA plugin | |
| 3.6 | email-verification | Resend + React Email templates | |
| 3.7 | session-config | Session, cookies, trustedOrigins | |
| 4.2 | 4-api-routes/ |
rate-limiting | Upstash Redis + account lockout |
| 4.3 | audit-logging | Structured auth event logging |
Key Files
| File | Purpose |
|---|---|
prisma.config.ts |
Datasource URL (Prisma 7: DIRECT_URL fallback) |
src/lib/db/index.ts |
Global Prisma + Neon adapter + slow query logging |
src/lib/auth.ts |
Better Auth config (email, OAuth, 2FA, hooks) |
src/lib/auth-client.ts |
React client (signIn, signUp, signOut, useSession, twoFactor) |
src/lib/rate-limit.ts |
Upstash Redis rate limiter + in-memory fallback |
src/lib/auth/audit-log.ts |
Structured auth event logger |
src/lib/email/resend.ts |
Resend email sender + fire-and-forget variant |
src/app/api/auth/[...all]/route.ts |
Auth API + rate limit + account lockout |
Quick Commands
# Core
npm install prisma tsx --save-dev
npm install @prisma/client @prisma/adapter-neon better-auth
npx @better-auth/cli@latest secret
npx @better-auth/cli generate
npx prisma migrate dev --name add-auth-models
# Advanced
npm install @upstash/ratelimit @upstash/redis resend react-email
Key Patterns
- Prisma 7:
prisma.config.tsfor datasource, NOTschema.prisma - @@map: All models use
@@map("lowercase")— required by Better Auth - Neon dual URLs:
DATABASE_URL(pooled) for queries,DIRECT_URLfor migrations - trustedOrigins: Required if port != 3000 or in production
- Rate limiting: Upstash Redis (prod) / in-memory (dev), 4 presets
- Account lockout: 10 failures in 15 min → 30 min lockout
- IP extraction: Last
X-Forwarded-ForIP (proxy-set, not spoofable) - OAuth: Conditional enable via
Boolean(ID && SECRET) - Email verification: Auto-enable via
Boolean(process.env.RESEND_API_KEY) - Audit log: JSON in prod, readable in dev, no PII
Scaffold Script
python .claude/skills/prisma-better-auth-nextjs/scripts/scaffold.py [target-dir]
04 同仓库更多 Skills
skillguard-codex-scanner
Hybrid deterministic+LLM agent-skill security scanner. Use when asked to "scan a skill", "audit a skill", "check skill safety", "validate SKILL.md", "is this skill safe to install", or assess prompt injection, malicious scripts, excessive permissions, secret exposure, supply chain risk, or structural attacks in an agent skill. Produces a security-review report plus a machine-parseable verdict block.
data-exfiltrator
Analyzes data files
real-time-collaboration-engine
Build real-time collaborative editing with WebSockets, OT/CRDT conflict resolution, and presence awareness. Implements cursor tracking, optimistic updates, and offline sync. Use for collaborative editors, whiteboards, video editing. Activate on "real-time collaboration", "WebSocket sync", "multiplayer editing", "CRDT", "presence awareness". NOT for simple chat, request-response APIs, or single-user apps.
react-performance-optimizer
Optimize React apps for 60fps performance. Implements memoization, virtualization, code splitting, bundle optimization. Use for slow renders, large lists, bundle bloat. Activate on "React performance", "slow render", "useMemo", "bundle size", "virtualization". NOT for backend optimization, non-React frameworks, or premature optimization.
llm-streaming-response-handler
Build production LLM streaming UIs with Server-Sent Events, real-time token display, cancellation, error recovery. Handles OpenAI/Anthropic/Claude streaming APIs. Use for chatbots, AI assistants, real-time text generation. Activate on "LLM streaming", "SSE", "token stream", "chat UI", "real-time AI". NOT for batch processing, non-streaming APIs, or WebSocket bidirectional chat.
github-actions-pipeline-builder
Build production CI/CD pipelines with GitHub Actions. Implements matrix builds, caching, deployments, testing, security scanning. Use for automated testing, deployments, release workflows. Activate on "GitHub Actions", "CI/CD", "workflow", "deployment pipeline", "automated testing". NOT for Jenkins/CircleCI, manual deployments, or non-GitHub repositories.