better-auth-best-practices

Configure Better Auth servers, clients, database adapters, sessions, and plugins for TypeScript applications.

1|Updated Apr 26, 2026
One-click install
npx skills add https://github.com/CarlosPavajeau/light --skill better-auth-best-practices-carlospavajeau
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/CarlosPavajeau/light/tree/main/.claude/skills/better-auth-best-practices
Command: npx skills add https://github.com/CarlosPavajeau/light --skill better-auth-best-practices-carlospavajeau

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, @better-auth/cli.

What problem does it solve? Setting up authentication in TypeScript projects involves many moving parts—database adapters, session storage, plugins, and environment variables—and misconfiguration leads to broken logins or security gaps. This Skill provides a structured reference for configuring Better Auth correctly the first time. ## Core Features & Use Cases - Server & Client Setup: Guides installation, auth.ts creation, route handlers, and framework-specific client imports for React, Vue, Svelte, and Solid. - Database & Session Management: Covers Drizzle, Prisma, and MongoDB adapters, secondary storage with Redis, cookie cache strategies (compact, JWT, JWE), and stateless mode. - Plugins & Security: Documents plugin imports for two-factor, organization, passkey, and magic link, plus rate limiting, CSRF, and secure cookie options. - Use Case: You are adding email/password and Google OAuth login to a TanStack Start app with a PostgreSQL database. Use this Skill to generate the auth.ts config, run the CLI migration, and wire up the React client with correct session handling. ## Quick Start Set up Better Auth in my TypeScript app with email and password login, a Drizzle database adapter, and session management.

Frequently Asked Questions about better-auth-best-practices

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

FAQPage Schema
How do I set up Better Auth with a database in TypeScript?

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, then create an auth.ts file passing a database connection or ORM adapter. Run npx @better-auth/cli@latest migrate to apply the schema, and verify with a GET request to /api/auth/ok.

How do I add plugins like two-factor authentication to Better Auth?

Import plugins from dedicated paths such as better-auth/plugins/two-factor rather than the barrel export, then add them to the plugins array in your auth config. Re-run the CLI migrate or generate command afterward so plugin schema changes are applied.

Does Better Auth support Drizzle and Prisma adapters?

Yes, Better Auth provides ORM adapters imported from better-auth/adapters/drizzle, better-auth/adapters/prisma, and better-auth/adapters/mongodb. Note that configuration uses the ORM model name, not the underlying database table name.

Why are my Better Auth sessions not stored in the database?

When secondaryStorage such as Redis is defined, sessions go there by default instead of the database. Set session.storeSessionInDatabase to true to also persist sessions to the database, or use cookieCache for fully stateless mode.

What is the difference between Better Auth cookie cache strategies?

Better Auth offers three cookie cache strategies: compact (base64url with HMAC, smallest size), jwt (readable signed tokens), and jwe (encrypted for maximum security). Custom session fields are never cached and are always re-fetched from the database.