auth/bootstrap_account.ts view source
(deps: BootstrapAccountDeps, provided_token: string, input: BootstrapAccountInput): Promise<BootstrapAccountResult> import {bootstrap_account} from '@fuzdev/fuz_app/auth/bootstrap_account.js'; Bootstrap the first account with keeper and admin privileges.
Uses an atomic bootstrap_lock UPDATE to prevent concurrent bootstrap
attempts (TOCTOU). The full flow runs in a single transaction:
- Read and verify the bootstrap token (before transaction)
- Hash the password (CPU-intensive, before transaction)
- Acquire the bootstrap lock atomically (inside transaction)
- Create account + actor
- Grant keeper and admin role_grants (no expiry,
granted_by = null) - Delete the token file (after commit, reported via
token_file_deleted)
deps
database, token path, filesystem callbacks, and password hashing
provided_token
the bootstrap token from the user
stringinput
username and password
returns
Promise<BootstrapAccountResult>
the created account, actor, and role_grants — or a bootstrap failure
mutates
bootstrap_lock row— flips `bootstrapped` to `true` atomicallyaccount / actor / role_grant tables— inserts the bootstrap account, actor, and the keeper + admin role_grantsfilesystem— deletes the bootstrap token file after commit (reported via `token_file_deleted`)