better-auth-best-practices

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

Updated Mar 14, 2026
One-click install
npx skills add https://github.com/Ishaq74/atomic --skill better-auth-best-practices-ishaq74
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Ishaq74/atomic/tree/main/.github/skills/best-practices
Command: npx skills add https://github.com/Ishaq74/atomic --skill better-auth-best-practices-ishaq74

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 configuration decisions—database adapters, session storage, plugins, email flows, and security options—where small mistakes cause broken logins or insecure deployments. This Skill provides a structured reference covering the full setup workflow and common pitfalls. ## Core Features & Use Cases - Setup Workflow: Step-by-step installation, environment variables, auth.ts creation, route handlers, and CLI migration with a verification endpoint. - Configuration Reference: Covers database adapters (Drizzle, Prisma, MongoDB, direct drivers), session storage strategies, cookie cache modes, hooks, rate limiting, and security options. - Plugin Guidance: Tree-shakeable plugin imports for two-factor, organization, passkey, magic link, admin, and more, plus client-side setup for React, Vue, Svelte, and Solid. - Use Case: You are adding email/password authentication with email verification and an organization plugin to an Astro SSR app. Use this Skill to configure the Drizzle adapter, set up sendVerificationEmail, run the CLI migration, and avoid the model-name vs table-name gotcha. ## Quick Start Ask the AI to set up Better Auth with email and password sign-in using a Drizzle adapter and generate the required auth.ts configuration.

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 email and password authentication?

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, create an auth.ts with a database and emailAndPassword enabled, add a route handler, then run the CLI migrate command. Verify the setup by calling GET /api/auth/ok.

How do I use Better Auth with Drizzle or Prisma?

Import the adapter from better-auth/adapters/drizzle or better-auth/adapters/prisma and pass your ORM instance as the database option. Run npx @better-auth/cli generate to create the schema, and re-run it after adding plugins.

Why does Better Auth fail when my table name differs from the model name?

Better Auth uses the ORM adapter model name, not the underlying database table name. If a Prisma model User maps to a table called users, configure modelName as "user" referencing the Prisma model, not "users".

Does Better Auth support session storage in Redis?

Yes, configure secondaryStorage with Redis or KV and sessions are stored there instead of the database. Set session.storeSessionInDatabase to true if you also want sessions persisted to the database.

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

Import plugins from dedicated paths like better-auth/plugins/two-factor for tree-shaking, add them to the plugins array, and re-run the CLI to update the schema. Client plugins go in createAuthClient.

When should I not rely on Better Auth cookie cache for session data?

Custom session fields are not stored in the cookie cache and are always re-fetched from the database. In fully stateless mode without a database, sessions live only in the cookie and end when the cache expires.