The @surrealdb/better-auth adapter works with all Better Auth plugins. Pass them in the plugins array of your Better Auth configuration:
A wider example combining several plugins:
Important
SurrealDB helper functions
When you use the organization plugin (with or without the teams option), schema generation also emits a set of fn::* SurrealQL functions you can call directly in your own queries, rules, and permissions. These functions are defined with IF NOT EXISTS, so re-running the generated schema is safe.
fn::auth::organization::*
These functions are emitted when the organization plugin is active.
| Function | Signature | Returns | Description |
|---|---|---|---|
fn::auth::organization::member_of | (userId: string, organizationId: string) | bool | True if the user is a member of the organisation. |
fn::auth::organization::get_role | (userId: string, organizationId: string) | option<string> | The member's role ("owner", "admin", "member"), or NONE if not a member. |
fn::auth::organization::has_role | (userId: string, organizationId: string, minRole: string) | bool | True if the user's role is equal to or senior to minRole (owner > admin > member). |
fn::auth::organization::members | (organizationId: string) | array | All members records for the organisation. |
fn::auth::organization::teams | (organizationId: string) | array | All teams records for the organisation (requires teams: { enabled: true }). |
fn::auth::organization::has_permission | (userId: string, organizationId: string, resource: string, action: string) | bool | True if the user's role has a custom permission for the given resource and action (requires dynamicAccessControl). |
fn::auth::team::*
These functions are emitted when teams: { enabled: true } is set on the organization plugin.
| Function | Signature | Returns | Description |
|---|---|---|---|
fn::auth::team::member_of | (userId: string, teamId: string) | bool | True if the user is a member of the team. |
fn::auth::team::members | (teamId: string) | array | All teamMembers records for the team. |