better-auth-best-practices

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

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/ZubairImtiaz3/Safar-E-Iman-Portal --skill better-auth-best-practices-zubairimtiaz3
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/ZubairImtiaz3/Safar-E-Iman-Portal/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/ZubairImtiaz3/Safar-E-Iman-Portal --skill better-auth-best-practices-zubairimtiaz3

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 plugin schemas—and small misconfigurations (like using table names instead of model names) cause hard-to-debug failures. This Skill provides a structured, version-aware reference for configuring Better Auth correctly. ## Core Features & Use Cases - Guided Setup Workflow: Step-by-step installation, environment variables, auth.ts creation, route handlers, and CLI migrations for built-in, Drizzle, and Prisma adapters. - Configuration Reference: Covers core options, session storage strategies (cookie cache, secondary storage, stateless mode), security settings, hooks, and rate limiting. - Plugin & Client Guidance: Tree-shakeable plugin imports, client setup for React/Vue/Svelte/Solid, and type inference patterns. - Use Case: You are adding email/password plus Google OAuth login to a Next.js app with a Drizzle/Postgres database. Use this Skill to generate the schema, run migrations, configure social providers, and avoid common pitfalls like forgetting to re-run the CLI after adding plugins. ## Quick Start Set up Better Auth in my Next.js project with email/password authentication and a PostgreSQL database using the Drizzle 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 with a database?

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, create an auth.ts with your database config, and add a route handler. Run npx auth@latest migrate for the built-in adapter, or npx auth@latest generate followed by drizzle-kit or prisma migrate for ORM adapters.

How do I add OAuth social providers in Better Auth?

Add a socialProviders object to your auth config with entries like google: { clientId, clientSecret }. On the client, call signIn.social() with the provider name. Ensure your baseURL and trustedOrigins are configured correctly for the OAuth callback.

Does Better Auth work with Drizzle and Prisma?

Yes, Better Auth provides ORM adapters imported from better-auth/adapters/drizzle and better-auth/adapters/prisma. For Drizzle, pass a db instance from drizzle() and a provider value of pg, mysql, or sqlite matching your driver.

Why does Better Auth use model names instead of table names?

Better Auth config references ORM model names, not underlying database table names. If your Prisma model User maps to a table called users, you must use modelName: "user" in the config, not "users".

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

Plugins can add their own database tables and fields, so the schema must be regenerated. Re-run npx auth@latest migrate or npx auth@latest generate after adding or changing plugins, then apply the migration with drizzle-kit or prisma.

Can Better Auth work without a database?

Yes, with no database configured and cookieCache enabled, Better Auth runs in fully stateless mode where sessions live only in signed cookies. The tradeoff is that logout relies on cache expiry and custom session fields are not cached.