# Overview

Use SurrealDB as the database behind Better Auth with the @surrealdb/better-auth adapter, including schema generation, transactions, and support for all Better Auth plugins.

[Better Auth](https://better-auth.com) is a comprehensive, framework-agnostic authentication and authorisation library for TypeScript. The `@surrealdb/better-auth` adapter lets you use SurrealDB as the database behind Better Auth: you pass it a single connected [`Surreal`](/docs/reference/javascript.md) client and Better Auth manages all of its table operations through the adapter.

The adapter supports schema generation, transactions, the full set of Better Auth WHERE operators, and every Better Auth plugin.

> [!NOTE]
> This section covers the **Better Auth** integration only. For SurrealDB's own sign-in, tokens, and permissions model, see [Security](/docs/learn/security.md).

> [!NOTE]
> The `@surrealdb/better-auth` adapter works with SurrealDB versions `v3.1.0` and later.

## Prerequisites

- SurrealDB 3.1 or later
- Better Auth 1.6.x
- Node.js 18+ or Bun 1.x

## Feature support

The adapter advertises the following capabilities to Better Auth:

| Capability | Supported |
|------------|-----------|
| JSON / object fields | Yes |
| Dates | Yes |
| Booleans | Yes |
| Arrays | Yes |

## Identifiers

By default, Better Auth generates string identifiers in JavaScript. The adapter stores them as SurrealDB [record IDs](/docs/reference/query-language/language-primitives/data-types/record-ids.md) and deserialises them back to strings when reading, so a record round-trips to your application as the plain string `id`.

UUIDs are also supported. Enable them in your Better Auth configuration:

```typescript
betterAuth({
    database: surrealAdapter({ db }),
    advanced: { database: { generateId: 'uuid' } },
});
```

Better Auth generates the UUID in JavaScript and passes it to the adapter, which stores and reads it transparently (it round-trips as the plain UUID string). SurrealDB does not mint the UUID natively, which is why the adapter reports `supportsUUIDs: false` to Better Auth: that flag means "the database generates UUIDs itself", not "UUIDs are unsupported".

Numeric (auto-increment) identifiers are not supported.

## In this section

- [Getting started](/docs/build/integrations/authentication/better-auth/getting-started.md) - Install the adapter, connect to SurrealDB, configure options, and generate your schema.

- [Plugins](/docs/build/integrations/authentication/better-auth/plugins.md) - Use any Better Auth plugin and call the SurrealQL helper functions generated for the organisation plugin.

- [Transactions & limitations](/docs/build/integrations/authentication/better-auth/transactions-and-limitations.md) - How transactions behave and the current limitations to be aware of.

## Sources

- [GitHub repository](https://github.com/surrealdb/better-auth)
- [npm package](https://www.npmjs.com/package/@surrealdb/better-auth)
- [Better Auth documentation](https://better-auth.com)
