better-auth-best-practices

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up authentication in TypeScript projects involves many moving parts—database adapters, session storage, OAuth providers, email flows, and security settings—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, environment variables, auth.ts creation, route handlers, and CLI schema migration. - Session & Security Configuration: Covers cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugins & Integrations: Documents tree-shakable plugin imports for two-factor auth, organizations, passkeys, magic links, OAuth, and more. - Use Case: You are adding email/password plus Google OAuth login to a TanStack Start app with a PostgreSQL database. Use this Skill to configure the adapter, social providers, session caching, and run the CLI migration correctly. ## Quick Start Set up Better Auth in my TypeScript app with email and password sign-in, a PostgreSQL database adapter, 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 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 with a GET request to /api/auth/ok.

How do I add OAuth social providers to Better Auth?▼

Add a socialProviders object to your auth config with provider keys like google, each containing clientId and clientSecret. On the client, call signIn.social() with the provider name to start the OAuth flow.

Does Better Auth work with Prisma and Drizzle ORMs?▼

Yes, Better Auth provides dedicated adapters imported from better-auth/adapters/prisma and better-auth/adapters/drizzle. Use the CLI generate command to create the schema, and reference ORM model names rather than underlying table names in config.

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

When secondaryStorage like Redis is defined, sessions go there by default instead of the database. Set session.storeSessionInDatabase to true to also persist sessions to the database alongside secondary storage.

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

Import the twoFactor plugin from the dedicated path better-auth/plugins/two-factor and add it to the plugins array in your auth config. Re-run the CLI migrate command afterward so the plugin's schema changes are applied.