Skip to content

kriasoft/better-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Better Auth Plugins

TypeScript License: MIT PRs Welcome Discord Sponsor

A collection of modular plugins extending Better Auth with specialized authentication features for modern TypeScript applications. Each plugin is designed to be lightweight, type-safe, and production-ready.

Available Plugins

Preview Release

In Active Development

๐Ÿšง The following plugins are currently under development:

  • Security & Compliance: abuse-detection, fraud-detection, compliance, backup-codes
  • User Management: impersonation, onboarding, session-management, subscription
  • Integrations: analytics, audit-log, connect, storage, webhooks, notifications
  • Access Control: rate-limit, consent
  • Development Tools: mcp

Quick Start

Installation

Install Better Auth and the plugins you need:

# Using Bun (recommended)
bun add better-auth better-call better-auth-feature-flags

# Using npm
npm install better-auth better-call better-auth-feature-flags

# Using pnpm
pnpm add better-auth better-call better-auth-feature-flags

Peer Dependencies

  • better-auth and better-call are peer dependencies.
  • better-call provides the API/middleware foundation used by Better Auth and this plugin. Better Auth depends on it and re-exports related types.
  • Installing both ensures version alignment and avoids resolution issues with strict package managers (e.g., pnpm).

Basic Setup

import { betterAuth } from "better-auth";
import { featureFlags } from "better-auth-feature-flags";

export const auth = betterAuth({
  database: {
    provider: "postgresql",
    url: process.env.DATABASE_URL,
  },
  plugins: [
    // Feature flags and access control
    featureFlags({
      // Optional static flags (server defaults)
      flags: {
        "premium-features": {
          default: false,
          enabled: false,
        },
        "beta-ui": {
          default: false,
          enabled: false,
        },
      },
    }),
  ],
});

Client Integration

import { createAuthClient } from "better-auth/client";
import { featureFlagsClient } from "better-auth-feature-flags/client";

const authClient = createAuthClient({
  plugins: [featureFlagsClient()],
});

// Check feature flags (simple boolean checks)
const hasPremiumFeatures =
  await authClient.featureFlags.isEnabled("premium-features");
const canUseBetaUI = await authClient.featureFlags.isEnabled("beta-ui");

// Evaluate multiple flags efficiently
const flags = await authClient.featureFlags.evaluateMany([
  "premium-features",
  "beta-ui",
  "new-dashboard",
]);

// Get all flags for current user
const allFlags = await authClient.featureFlags.bootstrap();

// Track flag usage for analytics
await authClient.featureFlags.track("premium-features", "viewed");

// Admin operations (requires proper permissions)
const adminFlags = await authClient.featureFlags.admin.flags.list();
await authClient.featureFlags.admin.flags.create({
  key: "new-feature",
  name: "New Feature",
  type: "boolean",
  defaultValue: false,
});

if (hasPremiumFeatures) {
  // Show premium features
}

Development

This monorepo uses Bun's built-in workspace support for managing all plugins.

Prerequisites

  • Bun >= 1.0.0
  • Node.js >= 20.0.0 (for compatibility)
  • PostgreSQL or compatible database

Setup

# Clone the repository
git clone https://github.com/kriasoft/better-auth.git
cd better-auth-plugins

# Install dependencies
bun install

# Migrate the database
bun run db:push

# Build all packages
bun run build

# Run development mode
bun run dev

# Type check all packages
bun run typecheck

Database Commands

bun run db:studio         # Open Drizzle Studio (database GUI)
bun run db:generate       # Generate migrations from schema changes
bun run db:push           # Push schema changes (development)
bun run db:migrate        # Run migrations (production)

Project Structure

better-auth-plugins/
โ”œโ”€โ”€ plugins/                # 18 standalone plugins
โ”‚   โ”œโ”€โ”€ abuse-detection/    โ”œโ”€โ”€ analytics/         โ”œโ”€โ”€ audit-log/
โ”‚   โ”œโ”€โ”€ backup-codes/       โ”œโ”€โ”€ compliance/        โ”œโ”€โ”€ connect/
โ”‚   โ”œโ”€โ”€ consent/            โ”œโ”€โ”€ feature-flags/     โ”œโ”€โ”€ fraud-detection/
โ”‚   โ”œโ”€โ”€ impersonation/      โ”œโ”€โ”€ mcp/               โ”œโ”€โ”€ notifications/
โ”‚   โ”œโ”€โ”€ onboarding/         โ”œโ”€โ”€ rate-limit/        โ”œโ”€โ”€ session-management/
โ”‚   โ”œโ”€โ”€ storage/            โ”œโ”€โ”€ subscription/      โ””โ”€โ”€ webhooks/
โ”œโ”€โ”€ apps/playground/        # Dev environment
โ”œโ”€โ”€ docs/                   # Documentation site
โ””โ”€โ”€ test/                   # Test suites

Plugin structure: src/{index,client,plugin,schema,types}.ts โ†’ tsup โ†’ dist/

Vendor Dependencies

This project includes reference implementations as Git submodules in the vendor/ directory. See vendor/README.md for details and license information.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (bun test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to your branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Support

License

Open source and free to use! This project is licensed under the MIT License - feel free to use it in your personal and commercial projects.