better-auth-best-practices

Configure Better Auth authentication flows in TypeScript projects.

Updated Jan 17, 2023
One-click install
npx skills add https://github.com/MjxOro/dotfiles --skill better-auth-best-practices-mjxoro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/MjxOro/dotfiles/tree/main/claude/.claude/skills/better-auth-best-practices
Command: npx skills add https://github.com/MjxOro/dotfiles --skill better-auth-best-practices-mjxoro

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Better Auth integration guidance reduces the friction of implementing a full-featured, secure authentication system in TypeScript projects by consolidating configuration, adapter selection, session strategies, and plugin setup into actionable best practices.

Core Features & Use Cases

  • Environment & config guidance: Clear rules for BETTER_AUTH_SECRET, BETTER_AUTH_URL, and when to prefer env vars over hardcoded options.
  • Database & adapter guidance: How to wire direct DB pools or ORM adapters (Prisma, Drizzle, Mongo) and the distinction between model names and table names.
  • Session strategies & security: Recommendations for secondary storage, cookie cache modes (compact, jwt, jwe), session lifetimes, and secure cookie settings.
  • Plugins, hooks & CLI: Best practices for adding plugins (passkeys, OAuth, two-factor), using hooks for lifecycle events, and running CLI commands for migrations and schema generation.
  • Use case: Configure a Next.js backend with Prisma, enable email/password and Google OAuth, store sessions in Redis, and run the CLI to apply schema migrations.

Quick Start

Generate a Better Auth configuration for a TypeScript project using Prisma, enable email/password and Google OAuth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL in your environment, and run the CLI migrate command.

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 configure Better Auth with Prisma in a TypeScript project?

To configure Better Auth with Prisma, you map ORM adapter models to your schema, set BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, and run CLI migrate commands to apply database changes for authentication flows.

What is the best way to manage sessions in Better Auth using secondary storage?

Managing sessions in Better Auth using secondary storage involves selecting cookie cache modes like compact, jwt, or jwe, configuring session lifetimes, and utilizing external stores like Redis to handle secure session caching strategies.

Can I use Better Auth plugins for two-factor authentication and OAuth?

Yes, you can use Better Auth plugins to add two-factor authentication, OAuth, and passkeys to your TypeScript application by configuring plugin-based features and utilizing hooks for lifecycle events during the authentication process.

Does Better Auth support Drizzle ORM adapters and MongoDB for authentication?

Better Auth supports Drizzle ORM adapters and MongoDB for authentication by wiring direct database pools or ORM adapters, distinguishing between model names and table names during schema generation and migration.

How do I set up environment variables for Better Auth in a Next.js backend?

Setting up environment variables for Better Auth in a Next.js backend requires defining BETTER_AUTH_SECRET and BETTER_AUTH_URL, preferring environment variables over hardcoded options to securely manage authentication configuration.