Better Auth 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 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
Note
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 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:
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
Install the adapter, connect to SurrealDB, configure options, and generate your schema.
Plugins
Use any Better Auth plugin and call the SurrealQL helper functions generated for the organisation plugin.
Transactions & limitations
How transactions behave and the current limitations to be aware of.