Skip to content

BeechCMS


BeechCMS / @beechcms/core / ISessionRepository

Interface: ISessionRepository ​

Methods ​

findActiveByHash() ​

findActiveByHash(tokenHash, nowTimestamp): Promise<RefreshTokenRecord | null>

Finds an active refresh token by its hash. nowTimestamp is compared against expiresAt and revokedAt to guarantee the token is both unexpired and not revoked before returning it.

Parameters ​

tokenHash ​

string

nowTimestamp ​

number

Returns ​

Promise<RefreshTokenRecord | null>


listActiveForUser() ​

listActiveForUser(userId, nowTimestamp, limit): Promise<ActiveSessionSummary[]>

Returns a paginated list of active sessions for the user, ordered newest first.

Parameters ​

userId ​

string

nowTimestamp ​

number

limit ​

number

Returns ​

Promise<ActiveSessionSummary[]>


revokeAllForUser() ​

revokeAllForUser(userId, nowTimestamp): Promise<void>

Revokes all active refresh tokens for a user. Must be called on password change to invalidate all existing sessions immediately.

Parameters ​

userId ​

string

nowTimestamp ​

number

Returns ​

Promise<void>


revokeByHash() ​

revokeByHash(tokenHash, nowTimestamp): Promise<boolean>

Marks a refresh token as revoked so it cannot be used again. Returns true if the token was found and revoked, false if it was already revoked or absent.

Parameters ​

tokenHash ​

string

nowTimestamp ​

number

Returns ​

Promise<boolean>


revokeById() ​

revokeById(sessionId, userId, nowTimestamp): Promise<boolean>

Revokes a specific session by its database ID, scoped to the owning user to prevent one user from revoking another user's sessions.

Parameters ​

sessionId ​

string

userId ​

string

nowTimestamp ​

number

Returns ​

Promise<boolean>


saveRefreshToken() ​

saveRefreshToken(record): Promise<void>

Stores a new refresh token record. Only the hash is persisted, never the plaintext.

Parameters ​

record ​

NewRefreshToken

Returns ​

Promise<void>