better-auth-best-practices

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

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

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 or security gaps. This Skill provides a structured reference for configuring Better Auth correctly the first time. ## Core Features & Use Cases - Server & Client Setup: Guides installation, 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 mode. - Plugins & Security: Documents tree-shakable plugin imports (twoFactor, organization, passkey, magicLink), rate limiting, CSRF settings, and hooks for custom logic. - Use Case: You are adding email/password plus Google OAuth login to a Hono API with a Drizzle/PostgreSQL backend. Use this Skill to configure the adapter, run the CLI migration, set trusted origins, and verify the setup with the /api/auth/ok endpoint. ## Quick Start Set up Better Auth in my TypeScript server with a Drizzle PostgreSQL adapter, email and password sign-in, and the two-factor authentication plugin.

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 environment variables, then create an auth.ts file passing a database connection or ORM adapter. Run npx @better-auth/cli@latest migrate to apply the schema, and verify with a GET request to /api/auth/ok.

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 migrate or generate command afterward so plugin schema changes are applied to your database.

Does Better Auth work with Drizzle and Prisma?▼

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

Why are my Better Auth sessions not stored in the database?▼

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

Can Better Auth run without a database?▼

Yes, stateless mode stores the session entirely in a signed or encrypted cookie using cookieCache strategies like compact, jwt, or jwe. The tradeoff is that logout relies on cache expiry and custom session fields are not cached.