better-auth-best-practices

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

Updated Jul 25, 2026
One-click install
npx skills add https://github.com/regisleandro/clara-financas --skill better-auth-best-practices-regisleandro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/regisleandro/clara-financas/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/regisleandro/clara-financas --skill better-auth-best-practices-regisleandro

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Setting up TypeScript authentication with Better Auth involves many moving parts—environment variables, database adapters, session strategies, plugins, and migrations—and misconfiguring any of them leads to broken logins, missing schema tables, or insecure sessions. This Skill provides a structured reference so you configure Better Auth correctly the first time. ## Core Features & Use Cases - Setup Workflow: Step-by-step installation, environment variables, auth.ts creation, route handlers, and CLI migrations for built-in, Drizzle, and Prisma adapters. - Session & Security Configuration: Guidance on cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugins & Hooks: Tree-shakable plugin imports (twoFactor, organization, passkey, magicLink, and more) plus endpoint and database hooks for custom logic. - Use Case: You are adding email/password and Google OAuth login to a Next.js app backed by Drizzle and PostgreSQL. Use this Skill to generate the schema with the CLI, wire the adapter, configure social providers, and avoid the common model-name-versus-table-name pitfall. ## Quick Start Set up Better Auth in my Next.js project with a Drizzle PostgreSQL adapter, email and password sign-in, and Google OAuth, then run the schema migration.

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?

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, create an auth.ts with your database config, and add a route handler. Run npx @better-auth/cli migrate for the built-in adapter, or generate schema for Drizzle or Prisma and apply it with their migration tools.

How do I add plugins to Better Auth?

Import plugins from dedicated paths like better-auth/plugins/two-factor for tree-shaking, then add them to the plugins array in your config. Re-run the CLI generate or migrate command afterward so the plugin's schema tables are created.

Does Better Auth work with Drizzle ORM?

Yes, import the adapter from better-auth/adapters/drizzle and pass a db instance created by drizzle(). The provider value must match your driver (pg, mysql, or sqlite), and you need a drizzle.config.ts pointing to the generated schema for drizzle-kit commands.

Why does Better Auth use the wrong table name?

Better Auth config uses ORM model names, not underlying database table names. If your Prisma model User maps to a table called users, set modelName to "user" (the Prisma reference), not "users".

Where are Better Auth sessions stored?

If secondaryStorage like Redis is defined, sessions go there instead of the database. Set session.storeSessionInDatabase to also persist to the DB, or use cookieCache with no database for a fully stateless mode.