better-auth-best-practices

Configures Better Auth authentication with database adapters, sessions, plugins, and security options.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Integrating authentication into a TypeScript application involves many configuration decisions—database adapters, session storage, cookie strategies, plugins, and security settings—where small mistakes cause broken logins or security gaps. This Skill provides a structured reference for configuring Better Auth correctly the first time. ## Core Features & Use Cases - Core Configuration Guidance: Covers environment variables, CLI commands, database adapters (Drizzle, Prisma, MongoDB, direct drivers), and the critical model-name vs table-name distinction. - Session & Security Setup: Explains session storage priority, cookie cache strategies (compact, JWT, JWE), rate limiting, CSRF, and cross-subdomain cookies. - Plugin & Client Integration: Documents tree-shakeable plugin imports (twoFactor, organization, passkey, magicLink), framework clients (React, Vue, Svelte), and type inference via $Infer.Session. - Use Case: You are adding authentication to a Next.js app backed by Drizzle ORM. Use this Skill to configure the Drizzle adapter, enable email/password sign-in, set up session cookie caching, and add the two-factor plugin without hitting common pitfalls. ## Quick Start Set up Better Auth in my TypeScript app with a Drizzle database adapter, email and password sign-in, and session cookie caching following best practices.

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 Drizzle ORM?

Import the adapter from better-auth/adapters/drizzle and pass your Drizzle instance to the database option. Run npx @better-auth/cli generate to create the schema, and re-run it whenever you add or change plugins.

How do I add two-factor authentication with Better Auth?

Import the twoFactor plugin from better-auth/plugins/two-factor and add it to the plugins array in your auth config. Import from dedicated plugin paths rather than better-auth/plugins to enable tree-shaking, then re-run the CLI to update the schema.

Does Better Auth support session storage in Redis?

Yes, configure secondaryStorage with Redis or KV to store sessions and rate limits outside the database. When secondaryStorage is defined, sessions go there by default; set session.storeSessionInDatabase to true to also persist them in the database.

Why does Better Auth use model names instead of table names?

Better Auth references ORM adapter model names, not underlying database table names. If your Prisma model User maps to a table named users, configure modelName as "user" (the Prisma reference), not "users".

Can Better Auth work without a database?

Yes, with no database configured and cookieCache enabled, Better Auth runs in fully stateless mode where sessions live only in signed cookies. Note that logout effectively happens on cache expiry, and custom session fields are not cached.