Getting Started

This guide will help you integrate Better Auth Infrastructure into your application.

Prerequisites

Before you begin, make sure you have:

  1. A working Better Auth installation
  2. An account & API Key from the Better Auth Infrastructure dashboard

Installation

Install the @better-auth/infra package:

npm install @better-auth/infra

Environment Variables

Once you've gotten the API Key from the infrastructure dashboard, go ahead and add the BETTER_AUTH_API_KEY environment variable in your production environment variables.

# Required: Your Better Auth Infrastructure API key
BETTER_AUTH_API_KEY=your_api_key_here

You can get your API key by signing-up and creating a new project in the Better Auth Infrastructure dashboard.

Server Setup

Basic Configuration

Add the dash() plugin to your Better Auth configuration:

import { betterAuth } from "better-auth";
import { dash } from "@better-auth/infra"; 

export const auth = betterAuth({
  // ... your existing Better Auth config
  plugins: [
    dash({ 
      apiKey: process.env.BETTER_AUTH_API_KEY, 
    }), 
  ],
});

If you're on pro plan or above, you can use the sentinel() plugin to enable security checks, abuse protection, and more:

import { betterAuth } from "better-auth";
import { dash, sentinel } from "@better-auth/infra";  

export const auth = betterAuth({
  plugins: [
    dash({ /* ... */ }),
    sentinel({ 
      apiKey: process.env.BETTER_AUTH_API_KEY, 
    }) 
  ],
});

Client Setup

Basic Client Configuration

Add the client plugins to your auth client:

import { createAuthClient } from "better-auth/client";
import { dashClient, sentinelClient } from "@better-auth/infra/client";

export const authClient = createAuthClient({
  plugins: [
    dashClient(),
    sentinelClient({
      autoSolveChallenge: true, // Automatically solve PoW challenges
    }),
  ],
});

Plugin Overview

  • dash() - Enables analytics tracking, audit logging, dashboard admin APIs, and more
  • sentinel() - Enables security checks and abuse protection

You can use either plugin independently, but using both together provides the full Better Auth Infrastructure experience.

Next Steps

Now that you have the basic setup, explore these topics: