39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
/**
|
|
* Repository for refresh token storage and lifecycle management.
|
|
* Handles creation, lookup, and cleanup of JWT refresh tokens.
|
|
*/
|
|
export type RefreshTokenMeta = {
|
|
ipAddress?: string;
|
|
userAgent?: string;
|
|
};
|
|
/**
|
|
* Stores a new refresh token for a user.
|
|
*/
|
|
export declare function create(userId: string, tokenHash: string, expiresAt: Date, meta?: RefreshTokenMeta): Promise<void>;
|
|
/**
|
|
* Finds a non-expired refresh token by its hash.
|
|
*/
|
|
export declare function findByTokenHash(tokenHash: string): Promise<{
|
|
user_id: string;
|
|
} | null>;
|
|
/**
|
|
* Deletes a single refresh token by its hash (logout / rotation).
|
|
*/
|
|
export declare function deleteByTokenHash(tokenHash: string): Promise<boolean>;
|
|
/**
|
|
* Deletes all refresh tokens for a user (e.g. on logout or password change).
|
|
*/
|
|
export declare function deleteByUserId(userId: string): Promise<void>;
|
|
/**
|
|
* Removes all refresh tokens that have passed their expiration time.
|
|
*/
|
|
export declare function deleteExpired(): Promise<void>;
|
|
/**
|
|
* Counts non-expired refresh tokens for a user (active sessions).
|
|
*/
|
|
export declare function countActiveByUserId(userId: string): Promise<number>;
|
|
/**
|
|
* Deletes the oldest active refresh tokens for a user (session eviction).
|
|
*/
|
|
export declare function deleteOldestSessions(userId: string, count: number): Promise<number>;
|
|
//# sourceMappingURL=refreshTokenRepository.d.ts.map
|