Skip to main content
zerotal

Documentation


Documentation / @zerotal/auth / EmailOtpBroker

Class: EmailOtpBroker

Defined in: auth/src/EmailOtpBroker.ts:46

Constructors

Constructor

new EmailOtpBroker(_opts): EmailOtpBroker

Defined in: auth/src/EmailOtpBroker.ts:51

Parameters

_opts

EmailOtpOptions

Returns

EmailOtpBroker

Methods

send()

send(email): Promise<void>

Defined in: auth/src/EmailOtpBroker.ts:61

Generate a code, store its hash (with a zeroed attempt counter), and email the plaintext.

Parameters

email

string

The recipient address; the code is stored keyed by this email.

Returns

Promise<void>


attempt()

attempt(email, code): Promise<boolean>

Defined in: 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

email

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).