Class OtpService<SendArgs>

Type Parameters

Hierarchy

  • OtpService

Constructors

Properties

_sendOtp?: SendOtpFn<SendArgs>
generateId: (() => string)

Type declaration

    • (): string
    • Returns string

generateSolution: (() => string)

Type declaration

    • (): string
    • Returns string

gracePeriod: number
hash: ((value) => string)

Type declaration

    • (value): string
    • Parameters

      • value: string

      Returns string

maxAttempts: number
storage: OtpStorage
storagePrefix: string
storageTtl: number
timeToResend: number
timeToSolve: number

Methods

  • Parameters

    • expiresAt: number

    Returns number

  • Check the solution of the token. Default behavior is to invalidate the token when it is solved correctly.

    Last option allowReuseOfSolvedToken allows to mark the token as solved instead of invalidating it, so that it can be checked inside another API route with getTokenInformation function. If this option is used, the developer is responsible to invalidating the token after use.

    Usefull when solved token will be sent to another endpoint. It is the only way to keep logic not pretaining to otp solving outside of otp endpoints, Otherwise everything goes through otp handlers and it gets messy very quickly. Simply send solved token to an API endpoint, and

    allowReuseOfSolvedToken should be set to true if validation of multiple tokens is required. For example, when phone and email needs to be validated before registration. While multiple otps are solved, we want to keep them existing in the cache before proceeding to registration

    Type Parameters

    • Data = unknown

    Parameters

    • token: string
    • solution: string
    • Optional extra: {
          allowReuseOfSolvedToken?: boolean;
      }
      • Optional allowReuseOfSolvedToken?: boolean

    Returns Promise<OtpResult<Data>>

    Throws

  • Parameters

    • token: string

    Returns Promise<string>

  • Recieves the current status of the token only if it exists, otherwise it throws

    Type Parameters

    • Data = unknown

    Parameters

    • token: string

    Returns Promise<OtpResult<Data>>

    Throws

  • Invalidate a token. Important to call this function when allowReuseOfSolvedToken is enabled when solution is checked

    Parameters

    • token: string

    Returns Promise<void>

    Throws

  • Issues a new token

    Type Parameters

    • Data = unknown

    Parameters

    • account: string
    • sendArgs: SendArgs

      arguments passed to sendOtp

    • Optional customData: Data

      any JSON-encodable data can be embedded into the token

    Returns Promise<OtpResult<Data>>

    Throws

  • Resends otp message and issues a new token

    Type Parameters

    • Data = unknown

    Parameters

    • token: string
    • sendArgs: SendArgs

      arguments passed to sendOtp

    Returns Promise<OtpResult<Data>>

    Throws

  • Parameters

    • account: string
    • solution: string
    • args: SendArgs

    Returns Promise<void>

  • Parameters

    • token: string
    • value: string

    Returns Promise<void>

Generated using TypeDoc