SurrealDB Docs Logo

Enter a search query

signup()

Signs up as a record user (formerly known as a scope user) to a specific access method.

Method Syntax
db.signup(credentials)

Arguments

ArgumentDescription
credentials

Variables used in a signup query.

Example usage

// Use the following statement to set up the access // // 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) ) // DURATION FOR TOKEN 15m, FOR SESSION 12h // ; use serde::Serialize; use surrealdb::engine::remote::ws::Ws; use surrealdb::opt::auth::Record; use surrealdb::Surreal; #[derive(Serialize)] struct Credentials<'a> { email: &'a str, pass: &'a str, } #[tokio::main] async fn main() -> surrealdb::Result<()> { let db = Surreal::new::<Ws>("127.0.0.1:8000").await?; let jwt = db .signup(Record { namespace: "test", database: "test", access: "account", params: Credentials { email: "info@surrealdb.com", pass: "123456", }, }) .await?; // ⚠️: It is important to note that the token should be handled securely and protected from unauthorized access. let token = jwt.as_insecure_token(); dbg!(token); Ok(()) }

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install