better-auth

Configure Better Auth authentication with sessions, social providers, and multi-factor options.

Updated Apr 5, 2023
One-click install
npx skills add https://github.com/fcalell/dotfiles --skill better-auth-fcalell
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth
Source: https://github.com/fcalell/dotfiles/tree/main/dot_claude/skills/better-auth
Command: npx skills add https://github.com/fcalell/dotfiles --skill better-auth-fcalell

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Modern web apps struggle to implement consistent authentication, session management, and multi-provider support in a type-safe, maintainable way. Better Auth provides an extensible schema and a plugin system to unify authentication concerns across frontend and backend.

Core Features & Use Cases

  • Extensible session schema: easily add custom fields (e.g., activeTenantId, activeWorkspaceId, role) to tailor sessions to your domain.
  • Plugin ecosystem: integrate twoFactor, passkey (WebAuthn), and optional features like organization for multi-tenant setups.
  • End-to-end guidance: server and client configuration examples, Hono handler integration, and automatic schema generation to keep type safety in sync.
  • Security-first defaults: CSRF protection guidance, secure cookies in production, and trusted origins configuration.
  • Use Case: SaaS apps with role-based access, tenant contexts, and secure social login flows.

Quick Start

Install better-auth, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, and integrate the server and client setup to begin authenticating users.

Frequently Asked Questions about better-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure type-safe session management for a multi-tenant web application?

To configure type-safe session management, use Better Auth to define an extensible schema with custom fields like activeTenantId. This generates a type-safe session schema across server and client boundaries for multi-tenant SaaS applications.

What is the best way to add multi-factor authentication like passkeys to a TypeScript backend?

The best way to add multi-factor authentication is by integrating the passkey (WebAuthn) and twoFactor plugins within a Better Auth setup. This extends the base authentication system to support secure, passwordless login flows.

How does Better Auth handle session management across server and client boundaries?

Better Auth handles session management by generating a unified, type-safe session schema that synchronizes across server and client boundaries. It uses environment variables like BETTER_AUTH_SECRET and secure cookies to maintain trusted origins in production.

Do I need specific environment variables to set up web authentication with Better Auth?

Yes, setting up web authentication requires the BETTER_AUTH_SECRET and BETTER_AUTH_URL environment variables. These variables establish the foundational security configuration and trusted origins before initializing the server and client.

Can I integrate social login providers and role-based access control in a single authentication setup?

Yes, you can integrate social login providers and role-based access control simultaneously. Better Auth's plugin ecosystem supports adding custom role fields to the session schema while managing social provider configurations in one setup.

What security defaults are applied for CSRF protection and secure cookies in production?

Security defaults include built-in CSRF protection guidance and the enforcement of secure cookies in production. The system relies on configuring trusted origins to safely manage authentication sessions across web environments.