Skip to content
NEW

Introducing SurrealDB Studio, the new official app of SurrealDB

Learn more

1/3

AUTH

Auth built into the database

Authentication and access control are part of the engine, not a service beside it. Define who can sign in and exactly what they can see - down to the row and the field - in SurrealQL, and enforce it inside the same transaction as the query.

01 |ACCESS CONTROL

Identity and permissions, defined in the query language

Sign-up and sign-in logic, token verification, and per-row rules all live in your schema - versioned with your data and enforced by the engine on every query.

DEFINE ACCESS account ON DATABASE TYPE RECORD
SIGNIN (
SELECT * FROM user WHERE email = $email
AND crypto::argon2::compare(pass, $pass)
);

-- After sign-in, $auth is the user's record, so table
-- permissions scope every query to it automatically:
SELECT * FROM order WHERE user = $auth.id;

RECORD ACCESS

Users authenticate against your own tables

DEFINE ACCESS turns SurrealDB into a web database: users sign up and sign in against the records you already have, with password hashing built in.

DEFINE ACCESS account ON DATABASE
TYPE RECORD
SIGNUP (
CREATE user SET
email = $email,
pass = crypto::argon2::generate($pass)
)
SIGNIN (
SELECT * FROM user WHERE
email = $email AND
crypto::argon2::compare(pass, $pass)
);

ROW-LEVEL PERMISSIONS

Rules travel with the data

Permissions are declared on the table and enforced by the engine, so the same rule protects every query, live subscription, and API call - there is no application layer to forget it.

DEFINE TABLE order PERMISSIONS
FOR select WHERE user = $auth.id
FOR create WHERE $auth.id != NONE;

DEFINE TABLE post SCHEMALESS PERMISSIONS
FOR select WHERE published = true OR user = $auth.id
FOR create, update WHERE user = $auth.id
FOR delete WHERE user = $auth.id OR $auth.admin = true;

FIELD-LEVEL CONTROL

Validate and constrain every field

Type, assert, and default each field in the schema. Constraints run on write, so bad or unauthorised data never lands.

DEFINE FIELD email ON TABLE user
TYPE string
ASSERT string::is_email($value);

DEFINE INDEX email ON TABLE user
FIELDS email UNIQUE;

Everything an auth layer needs, in the engine

Sign-in methods, token verification, and access scopes are first-class database objects - defined once and enforced everywhere.

02 |ONE ENGINE

No separate auth service to run

Bolt-on auth means a second system to deploy, a second place for rules to drift, and a network hop on every check. In SurrealDB, identity and permissions are evaluated where the data lives.

One source of truth

Access rules live in the schema beside the data they protect, versioned together and impossible to bypass from another client.

Enforced in the transaction

Permissions are checked by the engine on every query, live subscription, and API call - not by application code you have to remember to write.

No extra hop

There is no auth server to call before the database call. The check and the query are the same operation.

Keep exploring

GET STARTED

Build auth into your data, not beside it

Define access, permissions, and validation in SurrealQL and let the engine enforce them on every request.

SamsungNVIDIAAppleVerizonTencent

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

SurrealDB

The unified data layer for AI

Graph, vector, document, and relational in one engine.
Agent Memory that connects and retrieves context wherever your data lives.

Explore with AI

Stay in the loop

Tutorials, AI agent recipes, and product updates, every two weeks.

Independently verified

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

Trust Centre

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom