IdentityModule · library/auth/src/repos/auth-sessions.ts:27

AuthSessionsRepo

component

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 decorators
implementsinterfaces
@Userequires (1)
db: Db

Methods (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.

@paramopts{ userId: string; via: SessionViaValue; now: Date; ttlMs: number; maxTtlMs?: number; }
@returns{ token: string; expiresAt: string }

insert

insert(row: AuthSessionRow): void
@paramrowAuthSessionRow
@returnsvoid

findByTokenHash

findByTokenHash(tokenHash: string): AuthSessionRow | null
@paramtokenHashstring
@returnsAuthSessionRow | null

touch

touch(tokenHash: string, expiresAt: string): void

Sliding renewal: update the expiration time.

@paramtokenHashstring
@paramexpiresAtstring
@returnsvoid

delete

delete(tokenHash: string): void
@paramtokenHashstring
@returnsvoid

deleteExpired

deleteExpired(nowIso: string): void

Opportunistically clean up expired sessions (called during login/validation).

@paramnowIsostring
@returnsvoid

deleteByUser

deleteByUser(userId: string): void

Clear all sessions for a user (forces re-login after an admin resets the password).

@paramuserIdstring
@returnsvoid

deleteByUserAndVia

deleteByUserAndVia(userId: string, via: SessionViaValue): void

Clear 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.

@paramuserIdstring
@paramviaSessionViaValue
@returnsvoid