better-auth-best-practices

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

Updated Jul 8, 2026
One-click install
npx skills add https://github.com/NarixHine/uni-chem --skill better-auth-best-practices-narixhine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/NarixHine/uni-chem/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/NarixHine/uni-chem --skill better-auth-best-practices-narixhine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, @better-auth/cli.

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, schema mismatches, or security gaps. This Skill provides a structured reference for configuring 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 Configuration: Guidance on cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugin & Client Integration: Tree-shakeable plugin imports (twoFactor, organization, passkey, magicLink, etc.) and framework-specific clients for React, Vue, Svelte, and Solid. - Use Case: You are adding email/password plus Google OAuth login to a Next.js app backed by Prisma and Postgres. Use this Skill to generate the schema, wire the adapter, configure social providers, and avoid the common model-name vs table-name pitfall. ## Quick Start Ask the AI to set up Better Auth with email and password login using a Prisma adapter and Postgres database in your TypeScript project.

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 Prisma and PostgreSQL?▼

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, create auth.ts with the Prisma adapter, then run npx @better-auth/cli generate to output the schema and npx prisma migrate dev to apply it. 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 generate or migrate command afterward so the plugin's schema changes are applied.

Does Better Auth support Drizzle ORM as a database adapter?▼

Yes, import the adapter from better-auth/adapters/drizzle and pass a db instance created by drizzle(). The provider value must match your driver: pg for PostgreSQL, mysql for MySQL, or sqlite for SQLite, and drizzle-kit commands require a drizzle.config.ts.

Why does Better Auth use the wrong table name with my ORM?▼

Better Auth config references ORM model names, not underlying database table names. If your Prisma model is User mapping to a users table, use modelName "user" in the config rather than "users".

Where are Better Auth sessions stored by default?▼

If secondaryStorage such as Redis is defined, sessions go there instead of the database. Set session.storeSessionInDatabase to true to also persist to the DB, or use cookieCache with no database for a fully stateless mode.