Documentation / zerotal / auth / EmailOtpBroker
Class: EmailOtpBroker
Defined in: packages/auth/src/EmailOtpBroker.ts:46
Constructors
Constructor
new EmailOtpBroker(
_opts):EmailOtpBroker
Defined in: packages/auth/src/EmailOtpBroker.ts:51
Parameters
_opts
Returns
EmailOtpBroker
Methods
send()
send(
Promise<void>
Defined in: packages/auth/src/EmailOtpBroker.ts:61
Generate a code, store its hash (with a zeroed attempt counter), and email the plaintext.
Parameters
string
The recipient address; the code is stored keyed by this email.
Returns
Promise<void>
attempt()
attempt(
code):Promise<boolean>
Defined in: packages/auth/src/EmailOtpBroker.ts:78
Verify a code for an email. Returns true and consumes the code on success;
false when missing, expired, or wrong. Each wrong guess increments the
stored attempt counter; after maxAttempts failures the code is deleted so
an honest user can retry a typo, but a brute-forcer cannot walk the keyspace.
Parameters
string
The address the code was issued for.
code
string
The code entered by the user.
Returns
Promise<boolean>
true when the code is correct and unexpired (and is then consumed).