Skip to content

PrismaTokenStore

The TokenStore on the AuthToken model from prisma/auth.prisma.

  • TokenStore

new PrismaTokenStore(delegate): PrismaTokenStore

PrismaAuthTokenDelegate

PrismaTokenStore

consume(purpose, hash): Promise<StoredToken | null>

Atomically removes and returns the token: of many concurrent callers exactly one gets it.

string

string

Promise<StoredToken | null>

TokenStore.consume


deleteByUser(userId, purposes?): Promise<void>

Deletes the user’s tokens, of the given purposes or of every purpose.

string

readonly string[]

Promise<void>

TokenStore.deleteByUser


extendExpiry(purpose, hash, expiresAt, now): Promise<boolean>

Moves the expiry of the token with that hash to expiresAt, only if it still exists and has not expired (its expiry is after now), in one step; true when a token was changed. Never creates a token, so a token consumed meanwhile stays consumed, and never extends one that expired meanwhile. Optional for backward compatibility: without it OneTimeTokens.extendLink consumes the token and puts it back. That never revives a consumed token, but it hides the token for one round trip, overwrites a token of the same user and purpose issued in between (the put replaces it), and loses the token if the put fails after the consume. The conformance suite expects it.

string

string

number

number

Promise<boolean>

TokenStore.extendExpiry


find(purpose, hash): Promise<StoredToken | null>

string

string

Promise<StoredToken | null>

TokenStore.find


findByUser(purpose, userId): Promise<StoredToken | null>

string

string

Promise<StoredToken | null>

TokenStore.findByUser


incrementAttempts(purpose, userId, max): Promise<number | null>

Atomically increments the attempt count of the user’s token of that purpose if it is below max, returning the new count; null when it is missing or already at max. Of N concurrent callers at most max get a number.

string

string

number

Promise<number | null>

TokenStore.incrementAttempts


incrementAttemptsByHash(purpose, hash, max): Promise<number | null>

incrementAttempts for the token with that hash only: null when it is missing (consumed, or replaced by a newer token of the same user and purpose) or already at max. A code check counts its attempt on the code it read, so a code resent meanwhile is never charged for a guess at the old one. Optional for backward compatibility: without it the attempt is counted by user and purpose, which charges a code resent between the read and the count. The conformance suite expects it.

string

string

number

Promise<number | null>

TokenStore.incrementAttemptsByHash


put(token): Promise<void>

Stores the token, replacing any token of the same purpose for the same user. Concurrent puts never throw.

StoredToken

Promise<void>

TokenStore.put