Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica
Skip to main content

create_user

Function create_user 

Source
pub async fn create_user(
    users_db: &Database,
    instance: &Instance,
    username: impl AsRef<str>,
    password: Option<&str>,
) -> Result<(String, UserInfo, PrivateKey)>
Expand description

Create a new user account

This function:

  1. Optionally hashes the user’s password (if provided)
  2. Generates a device keypair for the user
  3. Creates a user database for storing keys (encrypted or unencrypted)
  4. Creates UserInfo and stores it in _users database with auto-generated UUID
  5. First-admin bootstrap: if no instance admin exists yet in _users.auth_settings, promotes this user by adding their pubkey as Admin(0) to the instance-admin system DBs (_users and _databases). Subsequent users land as non-admins.

§Arguments

  • users_db - The _users system database
  • instance - The Instance handle
  • username - Unique username for login
  • password - Optional password. If None, creates passwordless user (instant login, no encryption)

§Returns

A tuple of (user_uuid, UserInfo, root_private_key). The private key is the one just generated for this user; callers (e.g. Instance::create_backend or InstanceAdmin::create_user) can hand it straight to [build_user_session] to materialise a logged-in User without re-decrypting the key from storage.