better-auth-best-practices

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

Updated Aug 3, 2026
One-click install
npx skills add https://github.com/Mark-Atef/Nebu --skill better-auth-best-practices-mark-atef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Mark-Atef/Nebu/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/Mark-Atef/Nebu --skill better-auth-best-practices-mark-atef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up TypeScript authentication with Better Auth involves many moving parts—database adapters, session storage, plugins, and environment variables—and misconfiguration leads to broken migrations, session bugs, or security gaps. 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 variable configuration, auth.ts creation, route handlers, and CLI migrations for built-in, Drizzle, and Prisma adapters. - Session & Security Guidance: Covers cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugin & Client Integration: Documents tree-shakable plugin imports (twoFactor, organization, passkey, magicLink) and framework clients for React, Vue, Svelte, and Solid. - Use Case: You are adding email/password plus Google OAuth login to a Next.js app with a Drizzle/PostgreSQL backend. Use this Skill to generate the schema, run migrations, configure social providers, and verify the setup with the /api/auth/ok endpoint. ## Quick Start Set up Better Auth in my TypeScript app with a Drizzle PostgreSQL adapter, email and password sign-in, 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 with a Drizzle adapter?

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, then create auth.ts using drizzleAdapter with a db instance from drizzle(). Run npx @better-auth/cli generate to create the schema, then push or migrate with drizzle-kit.

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

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

Does Better Auth support session storage in Redis or KV stores?

Yes, the secondaryStorage option directs sessions to Redis or KV instead of the database. You can also set session.storeSessionInDatabase to persist to both, or use cookieCache for fully stateless sessions without a database.

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

Better Auth uses the ORM model name, not the underlying database table name. If your Prisma model is User mapping to a users table, configure modelName as "user" rather than "users".

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, the base URL of your app. Only define baseURL or secret in the config file when these environment variables are not set.