Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides Better Auth integration patterns for NestJS backend and Next.js frontend with Drizzle ORM and PostgreSQL. Use when setting up Better Auth with NestJS backend, integrating Next.js App Router frontend, configuring Drizzle ORM schema, implementing social login (GitHub, Google), adding plugins (2FA, Organization, SSO, Magic Link, Passkey), implementing email/password authentication with session management, or creating protected routes and middleware.
.claude/skills/giuseppe-trisciuoglio-better-auth/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | 93% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 147% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 84% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 44% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 38% | 0% |
Better Auth is a type-safe authentication framework for TypeScript supporting multiple providers, 2FA, SSO, organizations, and passkeys. This skill covers integration patterns for NestJS backend with Drizzle ORM + PostgreSQL and Next.js App Router frontend.
bash# Backend (NestJS) npm install better-auth @auth/drizzle-adapter drizzle-orm pg npm install -D drizzle-kit # Frontend (Next.js) npm install better-auth
See references/nestjs-setup.md for complete backend setup, references/plugins.md for plugin configuration.
bash npm install drizzle-orm pg @auth/drizzle-adapter better-auth npm install -D drizzle-kit
drizzle.config.ts)typescript import { defineConfig } from 'drizzle-kit'; export default defineConfig({ schema: './src/auth/schema.ts', out: './drizzle', dialect: 'postgresql', dbCredentials: { url: process.env.DATABASE_URL! }, });
bash npx drizzle-kit generate npx drizzle-kit migrate
Checkpoint: Verify tables created: psql $DATABASE_URL -c "\dt" should show user, account, session, verification_token tables.
typescript // src/auth/auth.instance.ts import { betterAuth } from 'better-auth'; import { drizzleAdapter } from '@auth/drizzle-adapter'; import as schema from './schema';
export const auth = betterAuth({ database: drizzleAdapter(schema, { provider: 'postgresql' }), emailAndPassword: { enabled: true }, socialProviders: { github: { clientId: process.env.AUTH_GITHUB_CLIENT_ID!, clientSecret: process.env.AUTH_GITHUB_CLIENT_SECRET!, } } });
typescript @Controller('auth') export class AuthController { @All('*') async handleAuth(@Req() req: Request, @Res() res: Response) { return auth.handler(req); } }
Checkpoint: Test endpoint GET /auth/get-session returns { session: null } when unauthenticated (no error).
lib/auth.ts)typescript import { createAuthClient } from 'better-auth/client'; export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_APP_URL! });
middleware.ts)typescript import { auth } from '@/lib/auth'; export default auth((req) => { if (!req.auth && req.nextUrl.pathname.startsWith('/dashboard')) { return Response.redirect(new URL('/sign-in', req.nextUrl.origin)); } }); export const config = { matcher: ['/dashboard/:path*'] };
Checkpoint: Navigating to /dashboard when logged out should redirect to /sign-in.
Add plugins from references/plugins.md:
twoFactor({ issuer: 'AppName', otpOptions: { sendOTP } })passkey({ rpID: 'domain.com', rpName: 'App' })organization({ avatar: { enabled: true } })magicLink({ sendMagicLink })sso({ saml: { enabled: true } })Checkpoint: After adding plugins, re-run migrations and verify new tables exist.
Input: Display user data in a Next.js Server Component.
tsx// app/dashboard/page.tsx import { auth } from '@/lib/auth'; import { redirect } from 'next/navigation'; export default async function DashboardPage() { const session = await auth(); if (!session) { redirect('/sign-in'); } return ( <div> <h1>Welcome, {session.user.name}</h1> <p>Email: {session.user.email}</p> </div> ); }
Output: Renders user info for authenticated users; redirects unauthenticated to sign-in.
Input: User has 2FA enabled and wants to sign in, marking device as trusted.
typescript// Server: Configure 2FA with OTP sending export const auth = betterAuth({ plugins: [ twoFactor({ issuer: 'MyApp', otpOptions: { async sendOTP({ user, otp }, ctx) { await sendEmail({ to: user.email, subject: 'Your verification code', body: `Code: ${otp}` }); } } }) ] }); // Client: Verify TOTP and trust device const verify2FA = async (code: string) => { const { data } = await authClient.twoFactor.verifyTotp({ code, trustDevice: true // Device trusted for 30 days }); if (data) { router.push('/dashboard'); } };
Output: User authenticated; device trusted for 30 days without 2FA prompt.
Input: Enable passkey (WebAuthn) authentication for passwordless login.
typescript// Server import { passkey } from '@better-auth/passkey'; export const auth = betterAuth({ plugins: [ passkey({ rpID: 'example.com', rpName: 'My App', }) ] }); // Client: Register passkey const registerPasskey = async () => { const { data } = await authClient.passkey.register({ name: 'My Device' }); }; // Client: Sign in with autofill const signInWithPasskey = async () => { await authClient.signIn.passkey({ autoFill: true, // Browser suggests passkey }); };
Output: Users can register and authenticate with biometrics, PIN, or security keys.
For more examples (backup codes, organizations, magic link, conditional UI), see references/plugins.md and references/passkey.md.
.env, add to .gitignoreopenssl rand -base64 32 for BETTER_AUTH_SECRETngrok for local testing)email, userId for performancenpx better-auth typegen for full TypeScript coverage.env to .gitignore; never commit OAuth secrets or DB credentialsreferences/nestjs-setup.md - Complete NestJS backend setupreferences/nextjs-setup.md - Complete Next.js frontend setupreferences/plugins.md - Plugin configuration (2FA, passkey, organizations, SSO, magic link)references/mfa-2fa.md - Detailed MFA/2FA guidereferences/passkey.md - Detailed passkey implementationreferences/schema.md - Drizzle schema referencereferences/social-providers.md - Social provider configuration| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 16,130 | 12,317 | -24% | 1 | 1 | 0% | 3,538 | 4,992 | +41% | 0 | 0 | — |
case-02 | fail→fail | 13,675 | 14,084 | +3% | 1 | 1 | 0% | 2,851 | 5,267 | +85% | 0 | 0 | — |
case-03 | pass→pass | 6,659 | 4,146 | -38% | 1 | 1 | 0% | 1,253 | 3,106 | +148% | 0 | 0 | — |
case-04 | pass→pass | 9,379 | 3,751 | -60% | 1 | 1 | 0% | 1,335 | 2,940 | +120% | 0 | 0 | — |
case-05 | fail→pass | 9,395 | 5,242 | -44% | 1 | 1 | 0% | 1,613 | 3,119 | +93% | 0 | 0 | — |
case-06 | fail→pass | 7,353 | 2,694 | -63% | 1 | 1 | 0% | 1,113 | 2,744 | +147% | 0 | 0 | — |
case-07 | pass→pass | 6,578 | 3,064 | -53% | 1 | 1 | 0% | 1,082 | 2,705 | +150% | 0 | 0 | — |
case-08 | fail→pass | 14,102 | 11,526 | -18% | 1 | 1 | 0% | 2,339 | 4,311 | +84% | 0 | 0 | — |
case-09 | fail→pass | 12,584 | 7,090 | -44% | 1 | 1 | 0% | 2,489 | 3,576 | +44% | 0 | 0 | — |
case-10 | fail→pass | 15,132 | 6,312 | -58% | 1 | 1 | 0% | 2,600 | 3,592 | +38% | 0 | 0 | — |
case-11 | fail→fail | 12,411 | 5,801 | -53% | 1 | 1 | 0% | 2,442 | 3,393 | +39% | 0 | 0 | — |
case-12 | fail→fail | 6,441 | 3,704 | -42% | 1 | 1 | 0% | 1,129 | 3,013 | +167% | 0 | 0 | — |
case-13 | pass→pass | 13,149 | 8,528 | -35% | 1 | 1 | 0% | 2,437 | 3,930 | +61% | 0 | 0 | — |
case-14 | fail→fail | 8,393 | 6,232 | -26% | 1 | 1 | 0% | 1,552 | 3,516 | +127% | 0 | 0 | — |
case-15 | fail→pass | 28,667 | 9,858 | -66% | 1 | 1 | 0% | 2,545 | 4,133 | +62% | 0 | 0 | — |
case-16 | fail→pass | 17,447 | 7,432 | -57% | 1 | 1 | 0% | 2,886 | 3,667 | +27% | 0 | 0 | — |
case-17 | fail→fail | 24,147 | 16,793 | -30% | 1 | 1 | 0% | 2,795 | 5,421 | +94% | 0 | 0 | — |
case-18 | pass→pass | 6,058 | 3,340 | -45% | 1 | 1 | 0% | 1,025 | 2,858 | +179% | 0 | 0 | — |
case-19 | pass→pass | 7,787 | 2,804 | -64% | 1 | 1 | 0% | 1,264 | 2,841 | +125% | 0 | 0 | — |
case-20 | pass→pass | 14,208 | 10,614 | -25% | 1 | 1 | 0% | 2,820 | 4,358 | +55% | 0 | 0 | — |
case-21 | pass→pass | 11,031 | 6,045 | -45% | 1 | 1 | 0% | 2,082 | 3,465 | +66% | 0 | 0 | — |
case-22 | pass→pass | 10,044 | 9,406 | -6% | 1 | 1 | 0% | 1,897 | 4,212 | +122% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +32 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.