docs/content/docs/infrastructure/getting-started.mdx
Before you begin, make sure you have:
1. A working [Better Auth](/docs/installation) installation
2. An account & API Key from the [Better Auth Infrastructure](/dashboard) dashboard
Install the `@better-auth/infra` package:
```package-install
@better-auth/infra
```
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.
```dotenv
# Required: Your Better Auth Infrastructure API key
BETTER_AUTH_API_KEY=your_api_key_here
```
<Callout>
You can get your API key by signing-up and creating a new project in the
[Better Auth Infrastructure dashboard](/dashboard).
</Callout>
Add the dash() plugin to your Better Auth configuration:
import { betterAuth } from "better-auth";
import { dash } from "@better-auth/infra"; // [!code highlight]
export const auth = betterAuth({
// ... your existing Better Auth config
plugins: [
dash({ // [!code highlight]
apiKey: process.env.BETTER_AUTH_API_KEY, // [!code highlight]
}), // [!code highlight]
],
});
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"; // [!code highlight]
export const auth = betterAuth({
plugins: [
dash({ /* ... */ }),
sentinel({ // [!code highlight]
apiKey: process.env.BETTER_AUTH_API_KEY, // [!code highlight]
}) // [!code highlight]
],
});
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
}),
],
});
For Expo or React Native clients, import from @better-auth/infra/native instead of @better-auth/infra/client. The native entry provides dashClient (same audit log APIs as the web client) and sentinelNativeClient.
import { createAuthClient } from "better-auth/client";
import { dashClient, sentinelNativeClient } from "@better-auth/infra/native";
export const authClient = createAuthClient({
baseURL: "https://your-api.example.com",
plugins: [
dashClient(),
sentinelNativeClient({
autoSolveChallenge: true,
}),
],
});
See Sentinel — Expo and React Native for more details.
dash() - Enables analytics tracking, audit logging, dashboard admin APIs, and moresentinel() - Enables security checks and abuse protectionYou can use either plugin independently, but using both together provides the full Better Auth Infrastructure experience.
Now that you have the basic setup, explore these topics: