Skip to main content
Version: 1.0.2

DEFINE SCOPE

DEFINE SCOPE statement

Setting scope access allows SurrealDB to operate as a web database. With scopes you can set authentication and access rules which enable fine-grained access to tables and fields.

Requirements

Statement syntax

SurrealQL Syntax
DEFINE SCOPE @name SESSION @duration SIGNUP @expression SIGNIN @expression

Example usage

Below shows how you can create a scope using the DEFINE SCOPE statement.

-- Enable scope authentication directly in SurrealDB
DEFINE SCOPE account SESSION 24h
SIGNUP ( CREATE user SET email = $email, pass = crypto::argon2::generate($pass) )
SIGNIN ( SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(pass, $pass) )
;