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:
- Optionally hashes the user’s password (if provided)
- Generates a device keypair for the user
- Creates a user database for storing keys (encrypted or unencrypted)
- Creates UserInfo and stores it in _users database with auto-generated UUID
- First-admin bootstrap: if no instance admin exists yet in
_users.auth_settings, promotes this user by adding their pubkey asAdmin(0)to the instance-admin system DBs (_usersand_databases). Subsequent users land as non-admins.
§Arguments
users_db- The _users system databaseinstance- The Instance handleusername- Unique username for loginpassword- 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.