better-auth

Implement Better Auth authentication with TypeScript, Next.js 16, and JWT tokens.

Updated Feb 8, 2026
One-click install
npx skills add https://github.com/ramshan00/hackaton --skill better-auth-ramshan00
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth
Source: https://github.com/ramshan00/hackaton/tree/main/Hackathon2-phase2/.claude/skills/better-auth
Command: npx skills add https://github.com/ramshan00/hackaton --skill better-auth-ramshan00

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, and includes references (resource) components.

What problem does it solve? Setting up authentication in a Next.js application involves many moving parts: session management, JWT tokens, route protection, and client-server integration. This Skill provides tested configuration patterns and code examples for implementing authentication with Better Auth, reducing trial-and-error setup. ## Core Features & Use Cases - Server and Client Setup: Configure Better Auth with database adapters, email/password authentication, and create typed auth clients for React components. - JWT and Bearer Tokens: Generate, sign, verify, and decode JWT tokens with configurable algorithms, expiration, issuers, and custom claims. - Next.js 16 Integration: Protect routes with middleware, validate sessions in Server Components, and secure API routes with token verification. - Use Case: You are building a Next.js dashboard that requires login. Use this Skill to set up email/password sign-in, protect /dashboard routes via middleware, and issue JWT tokens for your API endpoints. ## Quick Start Set up Better Auth in my Next.js 16 app with email/password login, JWT tokens, and middleware protection for the dashboard routes.

Frequently Asked Questions about better-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Better Auth with Next.js App Router?

Create an auth instance with betterAuth in lib/auth.ts, then expose it via a catch-all route at app/api/auth/[...betterAuth]/route.ts exporting GET and POST handlers. Validate sessions in Server Components using auth.api.getSession with headers from next/headers.

How to generate and verify JWT tokens with Better Auth?

Add the jwt plugin to your Better Auth config with algorithm, expiresIn, issuer, and audience options. On the client, use jwtClient from better-auth/client/plugins to call authClient.jwt.generate and authClient.jwt.decode.

Does Better Auth support middleware route protection in Next.js?

Yes, Better Auth works with Next.js middleware by calling auth.api.getSession with the request cookie headers. You can redirect unauthenticated users away from protected paths like /dashboard using the matcher config.

Can I use bearer tokens for API authentication with Better Auth?

Yes, the bearer plugin enables bearer token authentication with configurable expiration. Clients use bearerClient to generate access tokens and send them in the Authorization header for protected API calls.

Why does session validation fail in Next.js middleware?

Session checks fail when cookies are not forwarded correctly to auth.api.getSession. Pass the cookie header explicitly from the request, and ensure BETTER_AUTH_SECRET and DATABASE_URL environment variables are set.