Auth and Admin Services
Learn how to use Auth and Admin Services in LioranDB to manage users, roles, sessions, and administrative operations. Understand how to handle authentication, permissions, password management, and database-level admin tasks securely.
Service handles on LioranDBClient
The client exposes:
client.authclient.usersclient.rolesclient.clusterclient.backupsclient.settings
These are source-backed wrappers over the server HTTP API.
AuthService
Public methods:
login(username, password)refresh(refreshToken)logout()logoutAll()me()listSessions()revokeSession(sessionId)changePassword(newPassword, clearMustChange?)
login(username, password)
Authenticates with explicit credentials and stores tokens inside the client.
const login = await client.auth.login("admin", "your-password");
console.log(login.principal.username);
console.log(login.session.session_id);
console.log(login.accessToken.length > 0);
console.log(login.refreshToken.length > 0);
refresh(refreshToken)
Exchanges a refresh token for a fresh token pair.
const refreshed = await client.auth.refresh(previousRefreshToken);
console.log(refreshed.accessToken, refreshed.refreshToken);
logout()
Revokes the current session.
The docs test exercises this through both:
client.auth.logout()client.logout()
logoutAll()
Revokes all sessions for the current user.
The docs test also exercises the convenience alias:
client.logoutAll()
me()
Returns the current authenticated principal.
listSessions()
Returns the current user's active sessions.
revokeSession(sessionId)
Revokes one session by id.
The docs test creates an extra session specifically to verify this behavior.
changePassword(newPassword, clearMustChange?)
Changes the current user's password.
UsersService
Public methods:
list()create(input)get(userId)update(userId, input)delete(userId)resetPassword(userId, input)revokeSessions(userId)
CreateUserInput
The real exported type is:
interface CreateUserInput {
readonly username: string;
readonly password: string;
readonly roles?: readonly string[];
readonly must_change_password?: boolean;
}
create(input)
Creates a user record.
const user = await client.users.create({
username: "ops-user",
password: "SuperStrongPassword123!",
roles: ["read_only"],
must_change_password: false,
});
list()
Returns a readonly array of UserRecord.
get(userId)
Fetches one user by id.
update(userId, input)
The real exported update type is:
interface UpdateUserInput {
readonly enabled?: boolean;
readonly roles?: readonly string[];
readonly metadata?: Readonly<Record<string, string>>;
}
Example:
await client.users.update(user.id, {
enabled: true,
metadata: {suite: "docs-test"},
});
resetPassword(userId, input)
The real exported type is:
interface ResetUserPasswordInput {
readonly new_password: string;
readonly clear_must_change?: boolean;
}
revokeSessions(userId)
Revokes all sessions for the target user.
delete(userId)
Deletes the user.
RolesService
Public methods:
listPermissions()listRoles()createRole(input)getRole(roleId)updateRole(roleId, input)deleteRole(roleId)
Permission names
The real exported PermissionName union includes:
DatabaseListDatabaseCreateDatabaseDropCollectionListCollectionCreateCollectionDropDocumentReadDocumentInsertDocumentUpdateDocumentDeleteIndexListIndexCreateIndexDropQueryExecuteQueryExplainTransactionExecuteBackupListBackupCreateBackupDeleteBackupRestoreUserListUserCreateUserUpdateUserDeleteUserRotateCredentialsSettingsReadSettingsWriteClusterReadClusterManageMetricsReadAuditReadSessionListSessionRevokeSystemNamespaceAccess
Grant scopes
The real exported RoleGrantScope type is:
type RoleGrantScope =
| { readonly kind: "cluster" }
| { readonly kind: "database"; readonly database: string }
| {
readonly kind: "collection";
readonly database: string;
readonly collection: string;
};
CreateRoleInput
interface CreateRoleInput {
readonly name: string;
readonly grants: readonly PermissionGrant[];
}
listPermissions()
Returns the permission names the server currently advertises.
listRoles()
Returns a readonly array of RoleRecord.
createRole(input)
Example:
const role = await client.roles.createRole({
name: "readers",
grants: [
{
permission: "DocumentRead",
scope: {kind: "database", database: "default"},
},
],
});
getRole(roleId)
Current tested practical behavior:
- using the role
nameis the safest follow-up lookup
updateRole(roleId, input)
The real update shape is:
interface UpdateRoleInput {
readonly grants: readonly PermissionGrant[];
}
Current tested practical guidance:
- reuse your own original driver-shaped grants when updating
- do not assume every server role response can be round-tripped blindly back
into
updateRole()
deleteRole(roleId)
Current tested practical behavior:
- deleting by role
nameis the most reliable path
ClusterService
Public methods:
summary()nodes()partitions()health()readiness()checkpoint()compact()
summary()
Returns ClusterSummary:
interface ClusterSummary {
readonly node_id: number;
readonly state: string;
readonly nodes: readonly NodeConfigView[];
readonly partitions: number;
readonly protocol_version: number;
}
nodes()
Returns readonly NodeConfigView[].
partitions()
Returns readonly partition placement rows.
health()
Returns readonly PartitionHealthView[].
readiness()
Returns current readiness plus transitions.
checkpoint()
Triggers cluster checkpoint maintenance and returns an acknowledgment object.
Current practical interpretation:
- this is an admin trigger
- treat success as "request accepted"
- do not assume it means every internal durability task has fully drained before the response is returned
compact()
Triggers compaction maintenance and returns an acknowledgment object.
Current practical interpretation:
- this is also an admin trigger
- treat the response as acknowledgment rather than as a detailed compaction report
BackupsService
Public methods:
list()create(input?)get(backupId)delete(backupId)verify(backupId)restore(backupId, input)getRestoreJob(jobId)
BackupCreateInput
The real exported type is:
interface BackupCreateInput {
readonly label?: string;
readonly scope?: "cluster" | "local_node";
}
list()
Returns readonly BackupJobRecord[].
create(input?)
Creates a backup job and returns a BackupJobRecord.
Current docs-test-backed behavior:
create()returns a backup id immediately- production code should still poll
get(backupId)untilstatusbecomes"completed"before assuming the archive exists
const backup = await client.backups.create({
label: "docs-demo",
scope: "local_node",
});
get(backupId)
Returns the current BackupJobRecord.
The real record includes:
backup_idlabelbackup_typestatusrequested_bycreated_at_msstarted_at_mscompleted_at_msfailed_at_mserrorarchive_pathmanifest_pathsize_byteschecksum_sha256partition_snapshot_boundarytopology_tomlengine_versiondatabase_metadatacluster_completescope
verify(backupId)
Verifies the created archive and returns the updated BackupJobRecord.
The docs test now waits for completion first and then calls verify().
delete(backupId)
Deletes the archive and removes the stored backup job record.
The docs test now uses this to clean up backup files after exercising the API.
RestoreInput
The real exported type is:
interface RestoreInput {
readonly confirmation: string;
readonly disable_safety_backup?: boolean;
}
restore(backupId, input)
Schedules a restore and returns:
interface RestoreResponse {
readonly job: RestoreJobRecord;
readonly restart_required: boolean;
}
Current tested practical behavior:
- restore is a scheduled maintenance operation
- the server responds with
restart_required: true - follow-up state can be checked with
getRestoreJob(jobId)
Example:
const restore = await client.backups.restore(backup.backup_id, {
confirmation: `RESTORE ${backup.backup_id}`,
disable_safety_backup: true,
});
getRestoreJob(jobId)
Returns the scheduled restore job record.
The real exported restore record includes:
job_idbackup_idrequested_byconfirmationstatuscreated_at_msstarted_at_mscompleted_at_msfailurestaging_pathssafety_backup_idvalidation_resultsper_node_progress
SettingsService
Public methods:
get()update(values)getCors()updateCors(settings)getPerformance()updatePerformance(settings)getLimits()updateLimits(settings)getBackups()updateBackups(settings)
get()
Returns the generic redacted settings map.
update(values)
Patches the generic settings map.
getCors() and updateCors(settings)
Read and replace CorsSettings.
getPerformance() and updatePerformance(settings)
Read and replace PerformanceSettings.
Real exported performance fields include:
controller_interval_msquery_parallelism_capresult_batch_sizecompaction_permitscheckpoint_permitsreplication_batch_sizebackup_compression_concurrencyindex_warming_enabledbackground_work_enabledhigh_watermark_percentcritical_watermark_percentemergency_reserve_percent
getLimits() and updateLimits(settings)
Read and replace LimitSettings.
getBackups() and updateBackups(settings)
Read and replace BackupSettings.
Real exported backup settings include:
compression_levelverify_after_createrequire_cluster_completehourlydailyweeklymonthlyretention
Practical pattern: admin smoke test flow
The repository docs test currently exercises this rough flow:
- connect and authenticate
- create temp users and roles
- hit cluster summary, health, readiness, checkpoint, and compact
- read and round-trip settings
- create backup
- poll backup completion
- verify backup
- schedule restore
- inspect restore job
- delete backup artifacts during cleanup
That means the examples on this page are not just theoretical; they match the real end-to-end test coverage in the repository.