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.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "prisma-better-auth-nextjs" with this command: npx skills add clownnvd/claude-code-skills/clownnvd-claude-code-skills-prisma-better-auth-nextjs

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)

StepFolderFilesWhat
11-setup-project/create-nextjs-appCreate Next.js project
2.12-setup-prisma/install-dependenciesInstall Prisma + pg
2.2configure-prismaprisma.config.ts
2.3generate-clientGenerate typed client
2.4global-clientSingleton src/lib/db/index.ts
3.13-setup-better-auth/install-configureInstall + src/lib/auth.ts
3.2add-auth-modelsUser, Session, Account (with @@map)
3.3migrate-databaseRun migration
4.14-api-routes/setup-routesCatch-all + auth client
5.15-pages/sign-upSign up form
5.2sign-inSign in form
5.3dashboardProtected dashboard
5.4homeLanding page
66-test/test-appTest + troubleshoot

Steps Overview — Advanced (Production-Grade)

StepFolderFilesWhat
2.52-setup-prisma/neon-adapterNeon serverless adapter + dual URLs
2.6slow-query-loggingStructured slow query detection
3.43-setup-better-auth/oauth-providersGoogle + GitHub OAuth
3.5two-factorTOTP 2FA plugin
3.6email-verificationResend + React Email templates
3.7session-configSession, cookies, trustedOrigins
4.24-api-routes/rate-limitingUpstash Redis + account lockout
4.3audit-loggingStructured auth event logging

Key Files

FilePurpose
prisma.config.tsDatasource URL (Prisma 7: DIRECT_URL fallback)
src/lib/db/index.tsGlobal Prisma + Neon adapter + slow query logging
src/lib/auth.tsBetter Auth config (email, OAuth, 2FA, hooks)
src/lib/auth-client.tsReact client (signIn, signUp, signOut, useSession, twoFactor)
src/lib/rate-limit.tsUpstash Redis rate limiter + in-memory fallback
src/lib/auth/audit-log.tsStructured auth event logger
src/lib/email/resend.tsResend email sender + fire-and-forget variant
src/app/api/auth/[...all]/route.tsAuth 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.ts for datasource, NOT schema.prisma
  • @@map: All models use @@map("lowercase") — required by Better Auth
  • Neon dual URLs: DATABASE_URL (pooled) for queries, DIRECT_URL for 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-For IP (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]

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

ui-ux-pro-max

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

vercel-react-best-practices

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

stripe

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

nextjs

No summary provided by upstream source.

Repository SourceNeeds Review