# Audit Logs (/docs/infrastructure/plugins/audit-logs)

Track and query authentication events across your application with automatic audit logging.



Better Auth Infrastructure automatically collects audit logs for authentication events in your application. Once you've added the `dash()` plugin, events are tracked without any additional configuration.

## How Audit Logs Are Collected [#how-audit-logs-are-collected]

The `dash()` plugin hooks into your Better Auth instance and automatically records events as they happen. No manual instrumentation is needed — sign-ups, sign-ins, password changes, and more are all captured.

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

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

That's it. Once `dash()` is active, audit logs are collected automatically.

## Tracked Events [#tracked-events]

<Tabs items="[&#x22;User&#x22;, &#x22;Session&#x22;, &#x22;Account&#x22;, &#x22;Verification&#x22;, &#x22;Organization&#x22;, &#x22;Security&#x22;]">
  <Tab value="User">
    | Event                      | Trigger                                       |
    | -------------------------- | --------------------------------------------- |
    | `user_created`             | New user registration                         |
    | `profile_updated`          | User updates their profile                    |
    | `profile_image_updated`    | User changes their avatar                     |
    | `email_verified`           | Email verification completed                  |
    | `email_changed`            | User email address changed                    |
    | `user_banned`              | User is banned                                |
    | `user_unbanned`            | User is unbanned                              |
    | `user_role_updated`        | App-level user role changed                   |
    | `user_deleted`             | User account deleted                          |
    | `anonymous_user_converted` | Anonymous guest linked to a permanent account |
    | `two_factor_enabled`       | Two-factor authentication enabled             |
    | `two_factor_disabled`      | Two-factor authentication disabled            |
    | `two_factor_verified`      | Two-factor verification succeeded             |
  </Tab>

  <Tab value="Session">
    | Event                       | Trigger                         |
    | --------------------------- | ------------------------------- |
    | `user_signed_in`            | Successful sign-in              |
    | `user_signed_out`           | User signs out                  |
    | `user_sign_in_failed`       | Failed sign-in attempt          |
    | `session_created`           | New session created             |
    | `session_revoked`           | Single session revoked          |
    | `all_sessions_revoked`      | All sessions revoked            |
    | `user_impersonated`         | Admin starts impersonating user |
    | `user_impersonated_stopped` | Admin stops impersonating       |
  </Tab>

  <Tab value="Account">
    | Event              | Trigger                 |
    | ------------------ | ----------------------- |
    | `account_linked`   | Social account linked   |
    | `account_unlinked` | Social account unlinked |
    | `password_changed` | Password updated        |
  </Tab>

  <Tab value="Verification">
    | Event                      | Trigger                  |
    | -------------------------- | ------------------------ |
    | `password_reset_requested` | Password reset initiated |
    | `password_reset_completed` | Password reset finished  |
    | `email_verification_sent`  | Verification email sent  |
  </Tab>

  <Tab value="Organization">
    Tracked when using the [organization plugin](/docs/plugins/organization).

    | Event                                 | Trigger                          |
    | ------------------------------------- | -------------------------------- |
    | `organization_created`                | New organization created         |
    | `organization_updated`                | Organization settings changed    |
    | `organization_deleted`                | Organization deleted             |
    | `organization_member_added`           | Member added to organization     |
    | `organization_member_removed`         | Member removed from organization |
    | `organization_member_role_updated`    | Member role changed              |
    | `organization_member_invited`         | Invitation sent                  |
    | `organization_member_invite_accepted` | Invitation accepted              |
    | `organization_member_invite_rejected` | Invitation rejected              |
    | `organization_member_invite_canceled` | Invitation cancelled             |
    | `organization_team_created`           | Team created                     |
    | `organization_team_updated`           | Team updated                     |
    | `organization_team_deleted`           | Team deleted                     |
    | `organization_team_member_added`      | Member added to team             |
    | `organization_team_member_removed`    | Member removed from team         |
  </Tab>

  <Tab value="Security">
    Tracked when using the [Sentinel](/docs/infrastructure/plugins/sentinel) plugin.

    | Event             | Trigger                                                                                                                                                    |
    | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | `security_check`  | One event per protected user action. `eventData.outcome` is `passed`, `challenged`, or `blocked`. Includes `evaluatedChecks`, `triggeredBy`, and `reason`. |
    | `security_signal` | Informational detection detail for the Security dashboard. Does not count toward security usage.                                                           |
  </Tab>
</Tabs>

## Fetching Audit Logs [#fetching-audit-logs]

### Client setup [#client-setup]

Add `dashClient()` to your auth client:

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

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

### Get current user's audit logs [#get-current-users-audit-logs]

Returns audit events for the **current user**. Use this for end-user activity and org views where the caller is a normal member.

#### Query parameters [#query-parameters]

| Parameter        | Type     | Description                            |
| ---------------- | -------- | -------------------------------------- |
| `limit`          | `number` | Results per page (max 100, default 50) |
| `offset`         | `number` | Pagination offset (default 0)          |
| `organizationId` | `string` | Filter by organization                 |
| `identifier`     | `string` | Filter by identifier                   |
| `eventType`      | `string` | Filter by event type                   |
| `userId`         | `string` | Filter by user ID                      |
| `user`           | `object` | User object with ID                    |
| `session`        | `object` | Session object with user               |

#### Basic query [#basic-query]

```ts
const session = await authClient.getSession();

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

logs.data?.events;  // Array of audit log events
logs.data?.total;   // Total count
logs.data?.limit;   // Page size
logs.data?.offset;  // Current offset
```

#### Filter by event type [#filter-by-event-type]

Returns the current user's signed-in audit logs.

```ts
const signIns = await authClient.dash.getAuditLogs({
  session: session.data,
  eventType: "user_signed_in",
});
```

#### Filter by organization [#filter-by-organization]

Returns the current user's audit logs restricted to the given organization.

```ts
const orgLogs = await authClient.dash.getAuditLogs({
  session: session.data,
  organizationId: "org_123",
});
```

#### Combined filters [#combined-filters]

You can combine filters to get more specific results (e.g. all current user's signed-in events for a specific organization).

```ts
const orgSignIns = await authClient.dash.getAuditLogs({
  session: session.data,
  organizationId: "org_123",
  eventType: "user_signed_in",
});
```

You can also limit results to a specific identifier (e.g all current user's events for a specific org and email).

```ts
const orgSignIns = await authClient.dash.getAuditLogs({
  session: session.data,
  organizationId: "org_123",
  identifier: "user@example.com",
});
```

> **Note**: An identifier is a unique value for an event. For example, an email address, username, etc.

#### Pagination [#pagination]

Results are paginated. If you need to consume more than one page, you can use the `limit` and `offset` parameters to paginate the results:

```ts
async function fetchAllUserAuditLogEvents(session: unknown) {
  const limit = 100;
  let offset = 0;
  const allEvents = [];

  while (true) {
    const result = await authClient.dash.getAuditLogs({
      session: session.data,
      limit,
      offset,
    });
    
    const events = result.data?.events ?? [];
    allEvents.push(...events);

    if (events.length < limit) break;
    offset += limit;
  }

  return allEvents;
}
```

### Get all audit logs [#get-all-audit-logs]

Returns all audit events for organizations the current user has **admin** or **owner** access to. Use it for admin-style dashboards that need activity across organizations you manage.
You must use the [organization plugin](/docs/plugins/organization) so membership roles can be evaluated.

#### Query parameters [#query-parameters-1]

| Parameter        | Type     | Description                                                                        |
| ---------------- | -------- | ---------------------------------------------------------------------------------- |
| `limit`          | `number` | Results per page (max `100`, default `50`)                                         |
| `offset`         | `number` | Pagination offset (default `0`)                                                    |
| `organizationId` | `string` | Limit results to one organization (you must be owner or admin)                     |
| `userId`         | `string` | Limit to one user’s activity across organizations you administer as owner or admin |
| `eventType`      | `string` | Filter by event type                                                               |
| `identifier`     | `string` | Match `eventData.identifier` (organization-scoped actor identity)                  |
| `session`        | `object` | Session object with user                                                           |

#### Basic query [#basic-query-1]

```ts
const session = await authClient.getSession();

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

activity.data?.events;
activity.data?.total;
activity.data?.limit;
activity.data?.offset;
```

#### Filter by organization [#filter-by-organization-1]

Returns all audit events for the given organization:

```ts
const orgActivity = await authClient.dash.getAllAuditLogs({
  session: session.data,
  organizationId: "org_123",
});
```

#### Filter by user [#filter-by-user]

Returns all audit events for the given user across organizations:

```ts
const userActivity = await authClient.dash.getAllAuditLogs({
  session: session.data,
  userId: "user_456",
});
```

#### Filter by event type [#filter-by-event-type-1]

Returns all audit events across organizations for the given event type:

```ts
const events = await authClient.dash.getAllAuditLogs({
  session: session.data,
  eventType: "organization_member_invited",
});
```

#### Combined filters [#combined-filters-1]

You can combine filters to get more specific results (e.g. all audit events for a specific organization and event type).

```ts
const orgEvents = await authClient.dash.getAllAuditLogs({
  session: session.data,
  organizationId: "org_123",
  eventType: "organization_member_invited",
});
```

#### Pagination [#pagination-1]

Results are paginated. If you need to consume more than one page, you can use the `limit` and `offset` parameters to paginate the results:

```ts
async function fetchAllAuditLogs(session: unknown) {
  const limit = 100;
  let offset = 0;
  const allEvents = [];

  while (true) {
    const result = await authClient.dash.getAllAuditLogs({
      session: session.data,
      limit,
      offset,
    });
    
    const events = result.data?.events ?? [];
    allEvents.push(...events);

    if (events.length < limit) break;
    offset += limit;
  }

  return allEvents;
}
```

