Skip to content

RedisTwoFactorStore

The TwoFactorStore on Redis.

  • TwoFactorStore

new RedisTwoFactorStore(redis, options?): RedisTwoFactorStore

Redis

RedisStoreOptions = {}

RedisTwoFactorStore

addTrustedDevice(device, maxPerUser): Promise<void>

Stores a trusted device, then deletes the user’s oldest devices beyond maxPerUser. May drop it after expiresAt.

StoredTrustedDevice

number

Promise<void>

TwoFactorStore.addTrustedDevice


advanceStep(userId, step): Promise<boolean>

Compare-and-set: sets lastStep to step only if the factor is confirmed and its lastStep is below step, in one atomic write. Of many concurrent callers with the same step, at most one gets true.

string

number

Promise<boolean>

TwoFactorStore.advanceStep


confirmFactor(userId, secret, step): Promise<boolean>

Compare-and-set: confirms the factor and sets lastStep to step only if it is still pending and its secret still equals secret, in one atomic write. Returns whether it did.

string

string

number

Promise<boolean>

TwoFactorStore.confirmFactor


consumeRecoveryCode(userId, hash): Promise<boolean>

Removes one recovery code atomically: of many concurrent callers exactly one gets true.

string

string

Promise<boolean>

TwoFactorStore.consumeRecoveryCode


countRecoveryCodes(userId): Promise<number>

string

Promise<number>

TwoFactorStore.countRecoveryCodes


deleteFactor(userId): Promise<void>

Deletes the factor, pending or confirmed.

string

Promise<void>

TwoFactorStore.deleteFactor


deleteTrustedDevices(userId): Promise<void>

string

Promise<void>

TwoFactorStore.deleteTrustedDevices


findFactor(userId): Promise<StoredTotpFactor | null>

string

Promise<StoredTotpFactor | null>

TwoFactorStore.findFactor


findStepUp(sessionId): Promise<StoredStepUp | null>

The session’s step-up proof (expired or not: the caller checks).

string

Promise<StoredStepUp | null>

TwoFactorStore.findStepUp


findTrustedDevice(userId, hash): Promise<StoredTrustedDevice | null>

The device with this hash if it belongs to userId (expired or not: the caller checks).

string

string

Promise<StoredTrustedDevice | null>

TwoFactorStore.findTrustedDevice


putPendingFactor(factor): Promise<boolean>

Stores a pending (unconfirmed) factor with lastStep -1, replacing a pending one. Never replaces a confirmed factor: returns false (and writes nothing) when the user has one.

number

string

string

Promise<boolean>

TwoFactorStore.putPendingFactor


putStepUp(stepUp): Promise<void>

Stores (or replaces) the step-up proof of a session. May drop it after expiresAt.

StoredStepUp

Promise<void>

TwoFactorStore.putStepUp


replaceRecoveryCodes(userId, hashes): Promise<void>

Replaces the user’s recovery codes with hashes in one atomic write (an empty list deletes them).

string

readonly string[]

Promise<void>

TwoFactorStore.replaceRecoveryCodes