PrismaTokenStore
The TokenStore on the AuthToken model from prisma/auth.prisma.
Implements
Section titled “Implements”TokenStore
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PrismaTokenStore(
delegate):PrismaTokenStore
Parameters
Section titled “Parameters”delegate
Section titled “delegate”Returns
Section titled “Returns”PrismaTokenStore
Methods
Section titled “Methods”consume()
Section titled “consume()”consume(
purpose,hash):Promise<StoredToken|null>
Atomically removes and returns the token: of many concurrent callers exactly one gets it.
Parameters
Section titled “Parameters”purpose
Section titled “purpose”string
string
Returns
Section titled “Returns”Promise<StoredToken | null>
Implementation of
Section titled “Implementation of”TokenStore.consume
deleteByUser()
Section titled “deleteByUser()”deleteByUser(
userId,purposes?):Promise<void>
Deletes the user’s tokens, of the given purposes or of every purpose.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
purposes?
Section titled “purposes?”readonly string[]
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TokenStore.deleteByUser
extendExpiry()
Section titled “extendExpiry()”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.
Parameters
Section titled “Parameters”purpose
Section titled “purpose”string
string
expiresAt
Section titled “expiresAt”number
number
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”TokenStore.extendExpiry
find()
Section titled “find()”find(
purpose,hash):Promise<StoredToken|null>
Parameters
Section titled “Parameters”purpose
Section titled “purpose”string
string
Returns
Section titled “Returns”Promise<StoredToken | null>
Implementation of
Section titled “Implementation of”TokenStore.find
findByUser()
Section titled “findByUser()”findByUser(
purpose,userId):Promise<StoredToken|null>
Parameters
Section titled “Parameters”purpose
Section titled “purpose”string
userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<StoredToken | null>
Implementation of
Section titled “Implementation of”TokenStore.findByUser
incrementAttempts()
Section titled “incrementAttempts()”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.
Parameters
Section titled “Parameters”purpose
Section titled “purpose”string
userId
Section titled “userId”string
number
Returns
Section titled “Returns”Promise<number | null>
Implementation of
Section titled “Implementation of”TokenStore.incrementAttempts
incrementAttemptsByHash()
Section titled “incrementAttemptsByHash()”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.
Parameters
Section titled “Parameters”purpose
Section titled “purpose”string
string
number
Returns
Section titled “Returns”Promise<number | null>
Implementation of
Section titled “Implementation of”TokenStore.incrementAttemptsByHash
put(
token):Promise<void>
Stores the token, replacing any token of the same purpose for the same user. Concurrent puts never throw.
Parameters
Section titled “Parameters”StoredToken
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TokenStore.put