Dashboard

The `dash()` plugin connects your Better Auth instance to Better Auth Infrastructure, enabling analytics tracking, activity monitoring, event logging, and admin dashboard APIs.

The Dashboard plugin is the core connection between your Better Auth instance and Better Auth Infrastructure. It powers the web dashboard with real-time data, tracks user activity, and enables admin APIs.

What the Dashboard Plugin Enables

Once dash() is active, the Better Auth Infrastructure dashboard gives you:

  • User management — view, search, ban, and delete users
  • Session monitoring — see active sessions and revoke them
  • Organization overview — manage organizations and members
  • Analytics — track sign-ups, sign-ins, and active users over time
  • Audit logs — query event history (learn more)

Installation

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

export const auth = betterAuth({
  plugins: [
    dash(),
  ],
});

Configuration Options

DashOptions

OptionTypeDescription
apiUrlstringBetter Auth Infrastructure API URL. Default: https://dash.better-auth.com
kvUrlstringKV store URL. Default: https://kv.better-auth.com
apiKeystringYour API key for authentication. Falls back to BETTER_AUTH_API_KEY in env.
apiOptionsobjectDash API HTTP client options. Accepts timeout?: number in ms.
kvOptionsobjectKV HTTP client options. Accepts timeout?: number and retry?: { attempts?: number; ... }.
apiTimeoutnumberDeprecated alias for apiOptions.timeout.
kvTimeoutnumberDeprecated alias for kvOptions.timeout.
activityTrackingobjectActivity tracking configuration.
managedDirectorySyncobjectManaged directory-sync control-plane options.

Activity Tracking

Track when users were last active in your application. When enabled, a lastActiveAt field is automatically updated on user activity.

dash({
  apiKey: process.env.BETTER_AUTH_API_KEY,
  activityTracking: {
    enabled: true,
    updateInterval: 300000,  // Update interval in ms (default: 5 minutes)
  },
}),

Schema Changes

When activity tracking is enabled, the plugin adds a field to your user schema:

user: {
  fields: {
    lastActiveAt: {
      type: "date",
    },
  },
}

Enabling activity tracking requires a database migration for the lastActiveAt user field. Run the migration step before relying on activity data.

npx auth migrate

If your app manages schema generation separately, run npx auth generate and apply the generated migration with your preferred tool.

Managed Directory Sync

The managedDirectorySync option is the dashboard-side companion to the SCIM 1.7 plugin-managed runtime flow. When enabled is true, the dashboard installs the reservation tables and APIs needed for managed directory-sync state. ssoPairing enables the SSO hooks needed when a directory-backed user identity is paired with an SSO provider, and membershipProjection lets the system project SCIM membership changes into organization membership records.

dash({
  apiKey: process.env.BETTER_AUTH_API_KEY,
  managedDirectorySync: {
    enabled: true,
    ssoPairing: true,
    membershipProjection: {
      enabled: true,
      role: "member",
    },
  },
})

This opt-in control plane is for the SCIM 1.7 plugin-managed runtime flow. In Better Auth 1.7, SCIM supports three connection modes:

  • static code-defined connections
  • application-owned runtime verification
  • plugin-managed runtime connections via managedConnections

The managedDirectorySync option enables the plugin-managed mode for directory-sync provisioning in dash. It creates the reserved schema and APIs needed to manage directory connections and paired SSO state.

Managed directory sync options

OptionTypeDescription
enabledbooleanEnables the managed directory-sync control plane and the SCIM reservation tables / APIs. Default: false.
ssoPairingbooleanInstalls the SSO resolveUser and provider-mutation hooks required when a paired directory needs to reconcile a user identity through SSO. Default: true.
membershipProjectionobjectEnables SCIM-to-organization membership projection when a directory should create group or member membership records.
membershipProjection.enabledbooleanEnables the projection hook. Default: true.
membershipProjection.rolestringRole assigned to projected organization memberships. Default: "member".

Use this when the application wants Better Auth to manage the runtime tenant connection lifecycle for SCIM and pair it with SSO-based identity resolution. It is intended for the new 1.7 flow and complements scim({ managedConnections }).

Enabling managedDirectorySync requires the corresponding database migrations for the managed directory-sync tables. Run the migration step before using the managed runtime flow.

npx auth migrate

If your app manages schema generation separately, run npx auth generate and apply the generated migration with your preferred tool.

Database Schema

When managedDirectorySync.enabled is true, the dash plugin adds the following models. Better Auth supplies the primary id field for each model.

directorySyncConnection

Stores the managed directory's organization, SCIM connection, SSO pairing, lifecycle, and decommission state.

ColumnTypeConstraintsDescription
organizationIdstringRequired, indexedOrganization that owns the directory.
providerIdstringRequiredSSO provider identifier.
aliasKeystringRequired, unique, hiddenInternal directory alias.
provisioningDomainIdstringRequired, uniqueSCIM provisioning domain.
activeOrganizationKeystringRequired, unique, hiddenActive organization key for reconciliation.
connectionIdstringOptional, uniqueManaged SCIM connection identifier.
creationRequestIdstringRequired, unique, hiddenImmutable ownership correlation value.
statusstringRequiredCurrent directory lifecycle status.
revisionnumberRequired, default 0, hiddenMutation revision used for concurrency control.
createdAtdateRequiredCreation timestamp.
createdByActorIdstringRequiredActor that created the directory.
updatedAtdateRequiredLast update timestamp.
lastActorIdstringRequiredActor responsible for the latest mutation.
ssoProviderIdstringOptionalPaired SSO provider ID.
ssoProviderRecordIdstringOptional, indexedPaired SSO provider record.
activeSsoProviderKeystringRequired, unique, hiddenActive SSO provider key.
serializedSsoPairingstringOptional, hiddenSerialized SSO pairing metadata.
pairingEnforcedbooleanRequired, default falseWhether the SSO pairing requirement is enforced.
unpairedAtdateOptionalTime at which the directory was unpaired.
unpairedBystringOptionalActor that removed the pairing.
decommissionStartedAtdateOptionalTime decommissioning started.
decommissionedAtdateOptionalTime decommissioning completed.
lastErrorstringOptional, hiddenMost recent reconciliation error.

directorySyncMembershipProvenance

Tracks organization memberships created or managed by directory-sync projection so the plugin can reconcile only the memberships it owns.

ColumnTypeConstraintsDescription
membershipKeystringRequired, unique, hiddenStable key for the projected membership.
organizationIdstringRequired, indexedOrganization containing the membership.
userIdstringRequired, indexedBetter Auth User receiving the membership.
memberIdstringRequired, uniqueOrganization member record identifier.
ownershipstringRequired, hiddenProjection ownership state.
provisioningDomainIdstringRequired, indexedSCIM provisioning domain that produced it.
createdAtdateRequiredCreation timestamp.
updatedAtdateRequiredLast update timestamp.

For the full SCIM model and migration guidance, see the SCIM plugin reference and the 1.7 upgrade guide.

Event Tracking

The dash plugin automatically tracks the following events:

User Events

EventTrigger
user_signed_upNew user registration
user_profile_updatedUser updates their profile
user_profile_image_updatedUser changes their avatar
user_email_verifiedEmail verification completed
user_bannedUser is banned
user_unbannedUser is unbanned
user_deletedUser account deleted

Session Events

EventTrigger
user_signed_inSuccessful sign-in
user_signed_outUser signs out
session_createdNew session created
session_revokedSingle session revoked
sessions_revoked_allAll sessions revoked
user_impersonatedAdmin starts impersonating user
user_impersonation_stoppedAdmin stops impersonating

Account Events

EventTrigger
account_linkedSocial account linked
account_unlinkedSocial account unlinked
password_changedPassword updated

Verification Events

EventTrigger
password_reset_requestedPassword reset initiated
password_reset_completedPassword reset finished
email_verification_sentVerification email sent

Organization Events

If you're using the organization plugin, these events are also tracked:

EventTrigger
organization_createdNew organization created
organization_updatedOrganization settings changed
member_addedMember added to organization
member_removedMember removed from organization
member_role_updatedMember role changed
member_invitedInvitation sent
invite_acceptedInvitation accepted
invite_rejectedInvitation rejected
invite_cancelledInvitation cancelled
team_createdTeam created
team_updatedTeam updated
team_deletedTeam deleted
team_member_addedMember added to team
team_member_removedMember removed from team

Dashboard Endpoints

The dash plugin registers numerous admin endpoints for the dashboard:

User Management

EndpointMethodDescription
/dash/usersGETList users with pagination
/dash/users/online-countGETGet online users count
/dash/userGETGet user details
/dash/userPOSTCreate a new user
/dash/userPATCHUpdate user
/dash/userDELETEDelete user
/dash/user/banPOSTBan user
/dash/user/unbanPOSTUnban user
/dash/user/passwordPOSTSet user password
/dash/user/impersonatePOSTImpersonate user

Session Management

EndpointMethodDescription
/dash/sessionsGETList all sessions
/dash/sessionsDELETEDelete sessions
/dash/session/revokePOSTRevoke single session
/dash/sessions/revoke-allPOSTRevoke all user sessions

Organization Management

EndpointMethodDescription
/dash/organizationsGETList organizations
/dash/organizationGETGet organization details
/dash/organizationPOSTCreate organization
/dash/organizationPATCHUpdate organization
/dash/organizationDELETEDelete organization
/dash/organization/membersGETList members
/dash/organization/memberPOSTAdd member
/dash/organization/memberDELETERemove member
/dash/organization/member/rolePATCHUpdate member role

Team Management

EndpointMethodDescription
/dash/organization/teamsGETList teams
/dash/organization/teamPOSTCreate team
/dash/organization/teamPATCHUpdate team
/dash/organization/teamDELETEDelete team
/dash/organization/team/memberPOSTAdd team member
/dash/organization/team/memberDELETERemove team member

Invitation Management

EndpointMethodDescription
/dash/organization/invitationsGETList invitations
/dash/organization/invitePOSTSend invitation
/dash/organization/invite/cancelPOSTCancel invitation
/dash/organization/invite/resendPOSTResend invitation

SSO Management

EndpointMethodDescription
/dash/organization/sso-providersGETList SSO providers
/dash/organization/sso-providerPOSTCreate SSO provider
/dash/organization/sso-providerPATCHUpdate SSO provider
/dash/organization/sso-providerDELETEDelete SSO provider
/dash/organization/sso-provider/verify-domainPOSTVerify domain

Directory Sync

EndpointMethodDescription
/dash/organization/directoriesGETList directories
/dash/organization/directoryPOSTCreate directory
/dash/organization/directoryDELETEDelete directory
/dash/organization/directory/tokenPOSTRegenerate token

Log Drains

EndpointMethodDescription
/dash/organization/log-drainsGETList log drains
/dash/organization/log-drainPOSTCreate log drain
/dash/organization/log-drainPATCHUpdate log drain
/dash/organization/log-drainDELETEDelete log drain
/dash/organization/log-drain/testPOSTTest log drain

Events & Audit Logs

EndpointMethodDescription
/events/listGETGet user events
/events/audit-logsGETGet audit logs
/events/typesGETGet event types

Analytics

EndpointMethodDescription
/dash/statsGETGet user statistics
/dash/graphGETGet graph data
/dash/retentionGETGet retention data
/dash/mapGETGet geographic data

Two-Factor Management

EndpointMethodDescription
/dash/user/2fa/enablePOSTEnable 2FA for user
/dash/user/2fa/disablePOSTDisable 2FA for user
/dash/user/2fa/totp-uriGETGet TOTP URI
/dash/user/2fa/backup-codesGETView backup codes
/dash/user/2fa/backup-codes/generatePOSTGenerate new codes

Client Integration

dashClient()

The client plugin provides access to audit log queries:

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

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

Note: For Expo or React Native, import dashClient from @better-auth/infra/native (same API) and pair it with sentinelNativeClient as described in Sentinel — Expo and React Native.

Configuration

dashClient({
  resolveUserId: ({ userId, user, session }) => {
    return userId || user?.id || session?.user?.id;
  },
}),

Get the current user's audit logs

Returns audit events for the current user, or organization-scoped events when you pass organizationId as a member.

Basic query

const session = await authClient.getSession();

const logs = await authClient.dash.getAuditLogs({
  session: session.data,
  limit: 50,
  offset: 0,
});

// Access the data
console.log(logs.data?.events);  // Array of audit log events
console.log(logs.data?.total);   // Total count
console.log(logs.data?.limit);   // Page size
console.log(logs.data?.offset);  // Current offset

See Get current user's audit logs for more information.

Get all audit logs

Returns all audit events for organizations the current user has admin or owner access to. Requires the organization plugin for role checks.

Basic query

const session = await authClient.getSession();

const activity = await authClient.dash.getAllAuditLogs({
  session: session.data,
  limit: 50,
  offset: 0,
});

console.log(activity.data?.events);
console.log(activity.data?.total);

See Get all audit logs for more information.

Best Practices

  1. Always set an API key — without it, the plugin cannot communicate with the infrastructure API.

  2. Use activity tracking wisely — the update interval affects database writes. For high-traffic apps, consider a longer interval.

  3. Monitor audit log retention — different plans have different retention periods. Check your plan limits.

  4. Secure your endpoints — dashboard endpoints require authentication. Make sure your dashboard users have appropriate permissions.