better-auth-best-practices

Configure Better Auth for authentication workflows with database adapters and environment variables.

885|108|Updated Apr 30, 2025
One-click install
npx skills add https://github.com/legions-developer/invoicely --skill better-auth-best-practices-legions-developer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/legions-developer/invoicely/tree/main/.agents/skills/best-practices
Command: npx skills add https://github.com/legions-developer/invoicely --skill better-auth-best-practices-legions-developer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents broken or insecure Better Auth setups by guiding the correct configuration of database adapters, sessions, plugins, and required environment variables.

Core Features & Use Cases

  • End-to-end Better Auth setup: Configure server and client integration, including required env vars and a working auth.ts entry point.
  • Session and cookie strategy: Choose stateless vs database-backed sessions, configure cookie cache modes, and manage session expiration and refresh behavior.
  • Plugins, hooks, and security guardrails: Re-run migrations after plugin changes, wire endpoint/database hooks, and apply security-focused options and rate limiting.
  • Practical use case: When adding email/password auth and Google OAuth to an invoicing app, this guide helps you avoid adapter/model mapping mistakes and verify the /api/auth/ok health check.

Quick Start

Follow the instructions to create your auth.ts configuration, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, and run the CLI migrate command to validate that GET /api/auth/ok returns status ok.

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 database adapters and sessions?

Set up Better Auth by mapping ORM adapter modelNames correctly, choosing stateless or database-backed session storage, and defining required environment variables to establish secure authentication workflows.

Why does my Better Auth setup fail after adding plugins or hooks?

Your Better Auth setup likely fails because you need to run the CLI migrate or generate command after making plugin configuration changes to ensure the database schema matches your updated auth setup.

What environment variables do I need for Better Auth?

You need to set BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables for Better Auth to handle secrets and routing correctly across your web application authentication endpoints.

How do I verify my Better Auth configuration is working?

Verify your Better Auth configuration by running the CLI migrate command and checking the GET /api/auth/ok health check endpoint, which should return a status of ok if the setup is valid.

Can I use Better Auth for email/password and OAuth providers?

Yes, Better Auth supports configuring both email/password authentication and OAuth providers, allowing you to safely wire endpoints, apply security guardrails, and manage session expiration and refresh behavior.

What is the best way to manage session cookies in Better Auth?

The best way to manage session cookies in Better Auth is to configure cookie cache modes and define session expiration and refresh behavior based on your stateless or database-backed session strategy.