This package provides an official adapter for integrating SurrealDB with the Better Auth authentication library. It enables `better-auth` to persist user and session data within a SurrealDB instance, leveraging its capabilities for authentication flows. The current stable version is `1.0.0`, with a `2.0.0-beta` series actively under development, indicating a continuous release cadence. A key differentiator is its compliance with `better-auth`'s `createAdapter` utility, ensuring full compatibility with core features like CLI-based schema generation. It also offers advanced ID generation options, including `sdk.UUIDv4` and `sdk.UUIDv7`, providing flexibility in how records are identified within SurrealDB. The library is designed for modern JavaScript/TypeScript environments, requiring Node.js >=20.0.0 or Bun >=1.2.0, and relies on peer dependencies for `surrealdb` and `better-auth`.
npm install surreal-better-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `surreal-better-auth` adapter with a SurrealDB instance and integrate it into `better-auth`, configuring it with UUIDv7 for ID generation.
Ensure your adapter implementation or instantiation aligns with the `createAdapter` utility from `better-auth` as shown in the package's documentation. Review your adapter configuration for `idGenerator` options.
For production applications, it is generally recommended to stick to the latest stable release (v1.0.0) unless the beta features are critical and their potential for breaking changes is accepted. When using a beta, pin the exact version.
Ensure your SurrealDB instance is running, accessible, and the `db.signin` or `db.signup` calls are correctly executed with sufficient privileges for the database operations the adapter performs (e.g., creating/reading users and sessions).
If implementing a custom `idGenerator`, ensure it produces unique and valid SurrealDB record IDs. For most cases, `sdk.UUIDv7` is a good default choice for its ordered nature.
npm install surrealdb
npm install better-auth
Verify your SurrealDB server is running and accessible at the specified endpoint (e.g., `ws://localhost:8000/rpc`). Check your `db.signin` credentials and ensure they have database access.
Pass an initialized and connected `Surreal` client instance as the first argument to `createSurrealDBAdapter(db, options)`.