Better Auth - Next.js Showcase

A production-grade Next.js 15 authentication boilerplate that teaches modern auth patterns through a side-by-side client vs server contrast.

Didactic · 12-05-2026 · Next.js 15, React 19, TypeScript, better-auth, Prisma, Neon, PostgreSQL, OAuth2, GitHub OAuth, Google OAuth, Resend, Tailwind CSS v4, Server Actions, RSC, Edge Runtime, Turbopack, Vercel, MIT

Open source teaching boilerplate built end-to-end to make the tradeoffs between client-side and server-side authentication viscerally clear — two identical-looking dashboards, two completely different mechanics.

My Role

- Sole author: architecture, code, schema, deployment, and docs - Designed the pedagogical contrast: client useSession() + router.replace() vs server auth.api.getSession() + unauthorized() interrupt - Wired Prisma to Neon via the HTTP adapter (@prisma/adapter-neon) for Edge/serverless compatibility - Implemented email/password + GitHub + Google OAuth via better-auth - Added Resend-backed email verification with autoSignInAfterVerification - Patched React Server Components CVE vulnerabilities (security hardening pass) - Authored CLAUDE.md + README.md + .env.template so anyone can clone, configure, and run

Technical Highlights

- No middleware.ts by design — each protected route owns its session check, exposing the real cost/benefit tradeoff - Catch-all auth route at /api/auth/[...all] handles every better-auth HTTP call in 4 lines - experimental.authInterrupts enabled — unauthorized() throws a real HTTP 401 from RSC, renders app/unauthorized.tsx in place, preserves the URL, zero client flash - Server Actions for sign-out, multi-session revoke, and profile updates with revalidatePath() - Turbopack for both dev and build - Prisma schema with cascading deletes, FK indexes, unique constraints on email + token

Challenges Solved

- Two routes that look identical but behave oppositely — kept both in sync visually via a shared UnauthorizedScreen component - Neon HTTP driver vs TCP pitfall: @prisma/client alone silently falls back to TCP and breaks in Edge runtimes — fixed by mandating the adapter in the singleton - Resend sandbox gotcha: onboarding@resend.dev only delivers to the registered email — documented as a teaching point - Session truth boundary: enforced "better-auth is the only source of session truth" — no localStorage drift, no spoofable client state

Expertise Shown

✅ Mastery of the Next.js 15 App Router — RSC, Server Actions, route interceptors, experimental.authInterrupts ✅ Deep understanding of auth tradeoffs: client hooks vs server session resolution, 200 vs 401, URL preservation, content leak windows ✅ Edge/serverless database patterns with Neon's HTTP driver + Prisma adapter ✅ Security awareness: CVE remediation, env validation, no client-side auth state ✅ Teaching through code: deliberate architectural contrasts, embedded docs, MIT-licensed reusable seed

More projects