better-auth-best-practices

Configure Better Auth server and client with environment variables and database adapters.

Updated Dec 20, 2023
One-click install
npx skills add https://github.com/Thiago-Cruz-eng/Hibrygame --skill better-auth-best-practices-thiago-cruz-eng
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Thiago-Cruz-eng/Hibrygame/tree/main/.claude/skills/better-auth-best-practices
Command: npx skills add https://github.com/Thiago-Cruz-eng/Hibrygame --skill better-auth-best-practices-thiago-cruz-eng

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you configure Better Auth end to end without missing critical settings like secrets, adapters, session behavior, plugins, and required environment variables.

Core Features & Use Cases

  • Secure server and client configuration: Establishes the baseline auth setup with the right environment variables and configuration defaults.
  • Database adapters and model mapping: Guides correct adapter selection and the important distinction between ORM model names and underlying table names.
  • Session storage, cookie caching, and security controls: Helps you choose session persistence options, cookie cache strategies, and advanced security settings like secure cookies and CSRF/origin checks.
  • Plugins, hooks, and CLI workflow: Shows how to integrate common plugins, re-run migrations when plugins change, and use hooks for endpoint/database lifecycle behavior.

Quick Start

Configure your Better Auth server by defining BETTER_AUTH_SECRET and BETTER_AUTH_URL, creating the required auth.ts with your chosen database adapter, and running npx @better-auth/cli@latest migrate.

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 TypeScript and a database adapter?

To configure Better Auth, define BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, create an auth.ts file with your chosen database adapter, and run npx @better-auth/cli@latest migrate to generate the required schema.

What environment variables are required for Better Auth session management?

Better Auth session management requires setting BETTER_AUTH_SECRET for cryptographic signing and BETTER_AUTH_URL for the application's base URL to ensure correct session and cookie behavior across your web framework.

Does Better Auth support OAuth social providers and email/password authentication?

Yes, Better Auth supports both email/password and social OAuth provider integrations. You can configure these authentication methods within your auth.ts setup and apply optional plugins or hooks for extended endpoint behavior.

Why does Better Auth require mapping ORM model names to database table names?

Mapping ORM model names to underlying database table names in your Better Auth adapter ensures the CLI migration workflow correctly generates and updates your schema without conflicts between your ORM layer and actual database tables.

How do I run database migrations when adding Better Auth plugins?

When you add or change Better Auth plugins, you must re-run the CLI migration workflow using npx @better-auth/cli@latest migrate to update your database schema with the new required fields and tables.

Can I use Better Auth hooks to customize database lifecycle behavior?

Yes, Better Auth allows you to use hooks for customizing endpoint and database lifecycle behavior. You can integrate these hooks alongside plugins and session storage configurations to enforce advanced security controls like secure cookies and CSRF checks.