No JSDoc comment in source yet.
API
@Component()
export class AuthService implements Auth {
@Use() private readonly users!: Users;
@Use() private readonly authSessions!: AuthSessions;
@Use() private readonly state!: AuthState;
@Use() private readonly provisioner!: InitialProjectProvisioner;
@Use() private readonly config!: Config;
@Use() private readonly clock!: Clock;
@Use() private readonly hasher!: PasswordHasher;
get sessionTtlMs(): number;
setup(): void;
mintFirstLogin(): string | null;
async adminPasswordIs(password: string): Promise<boolean>;
async seedAdmin(): Promise<void>;
redeemFirstLogin(given: string): string | null;
adminPasswordIsInitial(): boolean;
async login(userId: string, password: string): Promise<{ user: UserInfo; token: string }>;
isAdmin(userId: string): boolean;
loginDesktop(): { user: UserInfo; token: string };
issueRemoteSession(): { token: string; expiresAt: string; maxAgeSeconds: number };
async changePassword(userId: string, oldPassword: string, newPassword: string): Promise<void>;
async setInitialPassword(userId: string, newPassword: string): Promise<void>;
logout(token: string): void;
localApiToken(): string | null;
authenticateApiToken(token: string): { user: UserRow; via: SessionVia } | null;
authenticateWithMeta(token: string): { user: UserRow; via: SessionVia; renewed: boolean } | null;
sessionIsLive(token: string): boolean;
}Dependencies & Wiring
Extracted from class decoratorsusers: Users · authSessions: AuthSessions · state: AuthState · provisioner: InitialProjectProvisioner · config: Config · clock: Clock · hasher: PasswordHasherMethods (17)
setup
setup(): voidvoidmintFirstLogin
mintFirstLogin(): string | nullNull once the server is claimed, so the only setup session that exists is a printed one. On demand rather than in the constructor: seedAdmin() runs after it, so "claimed?" has no answer there. A cached link whose row is gone is re-minted, not handed out dead.
string | nulladminPasswordIs
async adminPasswordIs(password: string): Promise<boolean>For the startup notice's pinned-seed gate (index.ts): a pin usually means the operator knows the password, but an offline reset makes it stale, and the gate must see through that or the rescue link stays suppressed.
stringPromise<boolean>seedAdmin
async seedAdmin(): Promise<void>Startup seeding (idempotent): creates the built-in admin and adopts default_project when the users table is empty; if the initial Project fails, the user row is rolled back and the server retries on next startup.
Promise<void>redeemFirstLogin
redeemFirstLogin(given: string): string | nullCompared against the printed value, not merely verified: a cookie made out of ANY valid token would let one person hand another a link into the sender's account. Not single-use, because a prefetching browser would burn it before its reader clicked.
stringstring | nulladminPasswordIsInitial
adminPasswordIsInitial(): booleanWhether the built-in admin still runs on its initial password (gates the first-login link).
booleanlogin
async login(userId: string, password: string): Promise<{ user: UserInfo; token: string }>stringstringPromise<{ user: UserInfo; token: string }>isAdmin
isAdmin(userId: string): booleanWhether a user is an admin, by id — for a caller that has a user's NAME rather than an authenticated request: the terminal relay reads the owner out of a pty reference the runtime has already matched against the signed-in user (machines/terminal-relay.ts), and what is left to decide is whether that user may reach machines at all. Unknown users are not admins.
stringbooleanloginDesktop
loginDesktop(): { user: UserInfo; token: string }Desktop-mode sign-in: an admin session with no password check — the claim route already redeemed the shell's one-shot token, which is the credential here. Throws only on a broken deployment (seeding runs before the route exists).
{ user: UserInfo; token: string }issueRemoteSession
issueRemoteSession(): { token: string; expiresAt: string; maxAgeSeconds: number }{ token: string; expiresAt: string; maxAgeSeconds: number }changePassword
async changePassword(userId: string, oldPassword: string, newPassword: string): Promise<void>Self password change (user settings): validates the old password first; the current session stays valid.
stringstringstringPromise<void>setInitialPassword
async setInitialPassword(userId: string, newPassword: string): Promise<void>No old-password check; the me route gates which sessions may call this.
stringstringPromise<void>logout
logout(token: string): voidEnds a session: the row is the session, so logout deletes it. Unknown token is a no-op.
stringvoidlocalApiToken
localApiToken(): string | nullThe current boot's local API token (what control-env injection hands to tool
subprocesses); null when none was minted. It lives on the runtime state, not on this
service: the token was written to <root>/api-token by the process, so it must
outlive the App a push replaces (auth/runtime-state.ts).
string | nullauthenticateApiToken
authenticateApiToken(token: string): { user: UserRow; via: SessionVia } | nullValidates a Bearer token against the boot's local API token (constant-time compare): a match authenticates as the built-in admin — holding the token proves filesystem access to the data root, which is admin authority (see auth/api-token.ts). Returns null on mismatch, when no token was minted, or when the admin row is missing.
string{ user: UserRow; via: SessionVia } | nullauthenticateWithMeta
authenticateWithMeta(token: string): { user: UserRow; via: SessionVia; renewed: boolean } | nullValidates the cookie token. Sliding renewal tops the expiry up IN PLACE, so the cookie value never changes and there is no second identity to revoke. Only a session whose own span reaches the renewal window slides — a one-hour minted token must expire at its hour, not stretch by being used.
string{ user: UserRow; via: SessionVia; renewed: boolean } | nullsessionIsLive
sessionIsLive(token: string): booleanWhether the session behind a cookie token still exists and has not expired — the same
two facts authenticateWithMeta establishes, without its sliding renewal or its
user lookup. A connection that outlives the request that opened it has to re-ask
periodically (the SSE heartbeat does, once per beat), and asking through the renewing
path would top the expiry up every time: a window nobody has touched since last week
would stay signed in purely because it is still connected.
stringboolean