better-auth-best-practices

Configures Better Auth authentication for TypeScript applications with plugins, sessions, and database adapters.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Integrating authentication into a TypeScript app involves many moving parts—session storage, OAuth providers, email flows, database adapters, and security settings. This Skill provides a condensed, accurate reference for configuring Better Auth correctly and avoiding common pitfalls like model-name mismatches and stale plugin schemas. ## Core Features & Use Cases - Configuration Reference: Covers core options, environment variables, database adapters (Prisma, Drizzle, MongoDB, SQL), and CLI commands for schema generation and migration. - Session & Security Guidance: Explains cookie cache strategies (compact, JWT, JWE), secondary storage, rate limiting, CSRF, and cross-subdomain cookies. - Plugin & Client Setup: Details tree-shakeable plugin imports (2FA, passkey, magic link, organization, SSO) and framework clients for React, Vue, Svelte, and Solid. - Use Case: When adding Google OAuth plus email/password login to a Next.js app with a Prisma database, use this Skill to configure the adapter, providers, session caching, and hooks without hitting the common gotchas. ## Quick Start Ask the AI to set up Better Auth with email/password and Google sign-in for your Next.js project using a Prisma database adapter.

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?▼

Create an auth.ts file, set BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, configure a database connection or ORM adapter, and enable providers like emailAndPassword or socialProviders. Run the CLI migrate or generate command to apply the schema.

How do I add Google or GitHub OAuth login with Better Auth?▼

Add the provider to the socialProviders option with its clientId and clientSecret, for example google or github. Better Auth supports many providers including Discord, Apple, Microsoft, and Twitter through the same configuration pattern.

Does Better Auth work with Prisma and Drizzle?▼

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

Why is my Better Auth session not persisting to the database?▼

When secondaryStorage is defined, sessions are stored there instead of the database by default. Set session.storeSessionInDatabase to true to also persist sessions to the database, or use cookieCache for stateless mode.

How do I add two-factor authentication or passkeys to Better Auth?▼

Import plugins from dedicated paths like better-auth/plugins/two-factor for tree-shaking, then add them to the plugins array. Re-run the CLI after adding plugins so the required schema changes are applied.