better-auth-best-practices

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

Updated May 7, 2026
One-click install
npx skills add https://github.com/Pieter-1337/Euricom-tsz --skill better-auth-best-practices-pieter-1337
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Pieter-1337/Euricom-tsz/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/Pieter-1337/Euricom-tsz --skill better-auth-best-practices-pieter-1337

SYSTEM DOCUMENTATION & REQUIREMENTS

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, auth.ts creation, route handlers, CLI migrations, and framework-specific client imports for React, Vue, Svelte, and Solid. - Session & Security Configuration: Covers cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugin & Database Guidance: Explains tree-shakable plugin imports (twoFactor, organization, passkey, etc.) and the critical model-name vs table-name distinction for Prisma and Drizzle adapters. - Use Case: You are adding email/password plus Google OAuth login to a Next.js app with a Prisma database. Use this Skill to generate the correct auth.ts, run the CLI migration, and avoid the common model-name mapping pitfall. ## Quick Start Set up Better Auth in my TypeScript app with email and password login, a PostgreSQL database, 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 npx @better-auth/cli@latest migrate to apply the schema.

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

Import plugins from dedicated paths like 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 the plugin schema is applied.

Does Better Auth work with Prisma and Drizzle ORMs?

Yes, Better Auth provides adapters imported from better-auth/adapters/prisma and better-auth/adapters/drizzle. Note that config uses the ORM model name, not the underlying table name, so a Prisma model User maps to modelName "user".

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

When secondaryStorage is defined, sessions go there by default instead of the database. Set session.storeSessionInDatabase to true to also persist sessions to the DB, or remove secondaryStorage to use database-only storage.

Can Better Auth run without a database?

Yes, stateless mode works without a database by storing sessions in the cookie cache using compact, JWT, or JWE strategies. The tradeoff is that logout only takes effect when the cache expires, and custom session fields are not cached.