.signin()
Signs in to a root, namespace, database or scope user.
Method Syntaxasync db.signin({`{ ... }`})
Properties | Description | ||
---|---|---|---|
username REQUIRED FOR ROOT, NAMESPACE & DATABASE | The username of the database user | ||
password REQUIRED FOR ROOT, NAMESPACE & DATABASE | The password of the database user | ||
namespace REQUIRED FOR DATABASE & SCOPE/ACCESS | The namespace to sign in to | ||
database REQUIRED FOR SCOPE/ACCESS | The database to sign in to | ||
scope 1.x | The scope to sign in to. Also pass any variables used in the scope. Only supported in SurrealDB 1.x | ||
access >=2.x | The access to sign in to. Also pass any variables used in the access. Only supported from SurrealDB 2.x onwards |
// Authenticate with a root user const token = await db.signin({ username: 'root', password: 'surrealdb', }); // Authenticate with a Namespace user const token = await db.signin({ namespace: 'surrealdb', username: 'tobie', password: 'surrealdb', }); // Authenticate with a Database user const token = await db.signin({ namespace: 'surrealdb', database: 'docs', username: 'tobie', password: 'surrealdb', }); // Authenticate with Record Access const token = await db.signin({ namespace: 'surrealdb', database: 'docs', access: 'user', // Also pass any properties required by the access definition variables: { email: 'info@surrealdb.com', pass: '123456', }, }); // Authenticate with Scopes const token = await db.signin({ namespace: 'surrealdb', database: 'docs', scope: 'user', // Also pass any properties required by the scope definition email: 'info@surrealdb.com', pass: '123456', });
You can invalidate the authentication for the current connection using the invalidate()
method. Learn more about handling authentication.