better-auth-best-practices

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

Updated Aug 2, 2026
One-click install
npx skills add https://github.com/JabezJesudasonJena/hack-ag --skill better-auth-best-practices-jabezjesudasonjena
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/JabezJesudasonJena/hack-ag/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/JabezJesudasonJena/hack-ag --skill better-auth-best-practices-jabezjesudasonjena

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, 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 across frameworks and ORMs. ## Core Features & Use Cases - Server & Client Setup: Guides installation, environment variables, auth.ts creation, route handlers, and framework-specific client imports (React, Vue, Svelte, Solid). - Database & Session Management: Covers Drizzle, Prisma, MongoDB, and direct driver adapters, plus session storage strategies including secondary storage, cookie caching, and stateless mode. - Plugins & Security: Documents plugin configuration (two-factor, organization, passkey, magic link), rate limiting, CSRF settings, hooks, and common pitfalls like model-name vs table-name mismatches. - Use Case: You are adding email/password and Google OAuth login to a NestJS or Next.js app with a Drizzle/Postgres database. Use this Skill to generate the schema, run migrations, configure social providers, and verify the setup with the /api/auth/ok endpoint. ## Quick Start Set up Better Auth in my TypeScript project with email/password login, a Drizzle Postgres 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 with a database?

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, then create an auth.ts file passing a database connection or ORM adapter. Run npx @better-auth/cli migrate for built-in adapters, or generate schema for Drizzle and Prisma before running their migrations.

How do I add OAuth social providers to 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 to start the OAuth flow.

Does Better Auth work with Drizzle and Prisma?

Yes, Better Auth provides dedicated adapters imported from better-auth/adapters/drizzle, better-auth/adapters/prisma, and better-auth/adapters/mongodb. Use the CLI generate command to create the schema, then run drizzle-kit or prisma migrate to apply it.

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

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

Where are sessions stored in Better Auth?

Sessions go to secondaryStorage (Redis/KV) if defined, otherwise to the database. With no database and cookieCache enabled, sessions run in fully stateless mode stored only in signed or encrypted cookies.

Do I need to re-run the CLI after adding Better Auth plugins?

Yes, you must re-run the CLI generate or migrate command after adding or changing plugins because plugins can add new tables and fields to the schema. Skipping this step causes runtime errors from missing columns.