better-auth-best-practices

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

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/Divith123/Flamingo --skill better-auth-best-practices-divith123
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Divith123/Flamingo/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/Divith123/Flamingo --skill better-auth-best-practices-divith123

SYSTEM DOCUMENTATION & REQUIREMENTS

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, security gaps, or schema mismatches. This Skill provides a structured reference for configuring Better Auth correctly the first time. ## Core Features & Use Cases - Server & Client Setup: Guides installation, environment variables, 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 session modes. - Plugins & Security: Documents tree-shakable plugin imports (twoFactor, organization, passkey, magicLink), rate limiting, CSRF settings, hooks, and common gotchas like model name vs table name mapping. - Use Case: You are adding email/password and Google OAuth login to a Next.js app with a Drizzle ORM database. Use this Skill to generate the auth.ts config, run the CLI schema generation, and wire up the client with correct plugin imports. ## Quick Start Set up Better Auth in my TypeScript project with email/password login, a Drizzle database adapter, and session cookie caching.

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 in a TypeScript project?▼

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, create an auth.ts file with your database and config, add a route handler for your framework, then run npx @better-auth/cli@latest migrate to apply the schema.

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

Import plugins from dedicated paths like better-auth/plugins/two-factor for tree-shaking, not from better-auth/plugins. Add them to the plugins array in your config, then re-run the CLI to update the database schema.

Does Better Auth work with Drizzle and Prisma ORMs?▼

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

Why is my Better Auth session not persisting to the database?▼

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

What environment variables does Better Auth require?▼

Better Auth requires BETTER_AUTH_SECRET, an encryption secret of at least 32 characters, and BETTER_AUTH_URL, your application's base URL. Only define baseURL or secret in config if these environment variables are not set.