better-auth-best-practices

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

Updated Mar 22, 2026
One-click install
npx skills add https://github.com/Ahmed-Eldalatony/airbnb-clone-bench --skill better-auth-best-practices-ahmed-eldalatony
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Ahmed-Eldalatony/airbnb-clone-bench/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/Ahmed-Eldalatony/airbnb-clone-bench --skill better-auth-best-practices-ahmed-eldalatony

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, and environment variables—where small mistakes cause broken logins or security gaps. This Skill provides a structured reference so you configure auth correctly the first time. ## Core Features & Use Cases - Server & Client Setup: Guides installation, environment variables, auth.ts creation, route handlers, and CLI migrations for any supported framework. - Session & Security Configuration: Covers cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugin Integration: Details tree-shakeable plugin imports for two-factor, organization, passkey, magic link, OAuth, and more, with client-side counterparts. - Use Case: You are adding email/password plus Google OAuth login to a Hono backend with a Drizzle database. Use this Skill to wire the adapter, run the schema migration, configure social providers, and verify the setup with the /api/auth/ok endpoint. ## Quick Start Set up Better Auth in my TypeScript project with email and password sign-in, a Drizzle database adapter, and session management.

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 in a TypeScript project?

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

How do I add OAuth social providers like Google to Better Auth?

Add a socialProviders object to your auth config with the provider name and its clientId and clientSecret, such as google: { clientId, clientSecret }. The client then calls signIn.social() to start the OAuth flow.

Does Better Auth work with Drizzle and Prisma ORMs?

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

Why do I need to re-run the Better Auth CLI after adding plugins?

Plugins can add their own database tables and fields, so the schema must be regenerated or migrated after any plugin change. Run npx @better-auth/cli@latest migrate or generate again to apply the updated schema.

Where are Better Auth sessions stored by default?

If secondaryStorage such as Redis or KV is defined, sessions go there instead of the database. Without a database, cookieCache enables a fully stateless mode where the session lives only in a signed or encrypted cookie.