better-auth-best-practices

Configure Better Auth server and client for session-backed TypeScript authentication.

6|4|Updated Nov 1, 2025
One-click install
npx skills add https://github.com/Montte-erp/montte-nx --skill better-auth-best-practices-montte-erp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/Montte-erp/montte-nx/tree/main/.agents/skills/better-auth-best-practices
Command: npx skills add https://github.com/Montte-erp/montte-nx --skill better-auth-best-practices-montte-erp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide removes uncertainty and repetitive trial-and-error when integrating Better Auth by providing a consolidated checklist and configuration guidance for server and client setup, database adapters, session strategies, plugins, and security hardening.

Core Features & Use Cases

  • Environment and CLI Workflow: Clear instructions for required environment variables, where to place auth.ts, and when to run the @better-auth/cli migrate and generate commands.
  • Database & Session Strategies: Guidance for direct DB connections, ORM adapters (Prisma/Drizzle/Mongo), secondary storage for sessions, and cookie cache strategies to balance security and performance.
  • Plugins, Hooks & Security: How to add and tree-shake plugins, configure hooks for pre/post actions, enforce secure cookies, rate limiting, and recommended safety flags for production deployments.
  • Use Case: Set up email/password and Google OAuth sign-in for a TypeScript web app, persist sessions in Redis, run migrations, and verify the health endpoint before launch.

Quick Start

Create an auth.ts with your chosen database adapter, set BETTER_AUTH_SECRET and BETTER_AUTH_URL in your environment, run the Better Auth CLI migrations, and verify the GET /api/auth/ok endpoint returns a status of 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 set up Better Auth with a database adapter in TypeScript?

To set up Better Auth, create an auth.ts file with your chosen ORM adapter like Prisma or Drizzle, set the required BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables, and run the @better-auth/cli migrate command to generate the database schema.

Why does my Better Auth session disappear after server restarts?

Better Auth sessions disappear after restarts if they are stored in memory instead of a persistent database or secondary storage. Configure a compatible database adapter or use a secondary storage solution like Redis to persist session data across server restarts.

Does Better Auth support OAuth providers like Google alongside email and password?

Yes, Better Auth supports OAuth providers alongside email and password authentication. You can configure social OAuth sign-in within your auth.ts file and use plugins to extend or tree-shake additional authentication methods as needed for your application.

When do I need to run the @better-auth/cli migrations?

You need to run the @better-auth/cli migrations whenever you initially set up your database schema or after modifying your auth configuration by adding plugins or changing adapters. Use the CLI migrate and generate commands to ensure your database structure matches your auth setup.

What's the best way to secure Better Auth cookies for production?

The best way to secure Better Auth cookies for production is to enforce secure cookie flags, implement rate limiting, and configure pre and post action hooks. You should also verify the GET /api/auth/ok health endpoint returns a status of ok before deploying.

Can I use Redis as secondary storage for Better Auth sessions?

Yes, you can use Redis as secondary storage for Better Auth sessions to balance security and performance. Configuring secondary storage allows you to offload session persistence from your primary database while maintaining secure, session-backed authentication.