No JSDoc comment in source yet.
API
@Component()
export class AuthSessionsRepo implements AuthSessions {
@Use() private readonly db!: Db;
issue(opts: {
userId: string;
via: SessionViaValue;
now: Date;
ttlMs: number;
maxTtlMs?: number;
}): { token: string; expiresAt: string };
insert(row: AuthSessionRow): void;
findByTokenHash(tokenHash: string): AuthSessionRow | null;
touch(tokenHash: string, expiresAt: string): void;
delete(tokenHash: string): void;
deleteExpired(nowIso: string): void;
deleteByUser(userId: string): void;
deleteByUserAndVia(userId: string, via: SessionViaValue): void;
}Dependencies & Wiring
Extracted from class decoratorsMethods (8)
issue
issue(opts: { userId: string; via: SessionViaValue; now: Date; ttlMs: number; maxTtlMs?: number; }): { token: string; expiresAt: string }Mints a session and returns the raw token for a cookie or the terminal. maxTtlMs caps a
caller-supplied lifetime (--ttl-seconds): one longer than an ordinary session would make
a leaked token file outlive every other credential, sliding forever. Expired rows are
swept here too, so a cron that only mints does not accumulate them.
{ userId: string; via: SessionViaValue; now: Date; ttlMs: number; maxTtlMs?: number; }{ token: string; expiresAt: string }insert
insert(row: AuthSessionRow): voidAuthSessionRowvoidfindByTokenHash
findByTokenHash(tokenHash: string): AuthSessionRow | nullstringAuthSessionRow | nulltouch
touch(tokenHash: string, expiresAt: string): voidSliding renewal: update the expiration time.
stringstringvoiddelete
delete(tokenHash: string): voidstringvoiddeleteExpired
deleteExpired(nowIso: string): voidOpportunistically clean up expired sessions (called during login/validation).
stringvoiddeleteByUser
deleteByUser(userId: string): voidClear all sessions for a user (forces re-login after an admin resets the password).
stringvoiddeleteByUserAndVia
deleteByUserAndVia(userId: string, via: SessionViaValue): voidClear a user's sessions of one kind. Used to end EVERY first-login session when a password
is set: an earlier boot's link may still be live in someone's scrollback, and a setup
session may change the password without knowing the old one.
stringSessionViaValuevoid