Documentation
    Preparing search index...

    Verification token class can be used to create tokens publicly shareable tokens while storing the token hash within the database.

    This class is used by the Auth and the Persona packages to manage tokens for authentication and authorization purposes.

    class UserToken extends VerificationToken {
    constructor(user: User, secret: Secret<string>) {
    super()
    this.tokenableId = user.id
    this.computeValue(secret)
    }
    }
    Index

    Constructors

    Properties

    identifier: string | number | BigInt

    Identifer is a unique sequence to identify the token within database. It should be the primary/unique key

    tokenableId: string | number | BigInt

    Reference to the user id for whom the token is generated.

    hash: string

    Hash is computed from the seed to later verify the validity of seed

    expiresAt: Date

    Timestamp at which the token will expire

    value?: Secret<string>

    The value is a public representation of a token. It is created by combining the "identifier"."secret" via the "computeValue" method

    Methods

    • Decodes a publicly shared token and return the series and the token value from it.

      Returns null when unable to decode the token because of invalid format or encoding.

      Parameters

      • value: string

        The token string to decode

      Returns null | { identifier: string; secret: Secret<string> }

    • Creates a transient token that can be shared with the persistence layer.

      Parameters

      • userId: string | number | BigInt

        The user ID for whom the token is being created

      • size: number

        The size of the random token seed

      • expiresIn: string | number

        Token expiration time (string like '2h' or number in seconds)

      Returns {
          userId: string | number | BigInt;
          expiresAt: Date;
          secret: Secret<string>;
          hash: string;
      }

    • Creates a secret opaque token and its hash.

      Parameters

      • size: number

        The length of the random token to generate

      Returns { secret: Secret<string>; hash: string }

    • Verifies the value of a token against the pre-defined hash

      Parameters

      • secret: Secret<string>

        The secret to verify against the stored hash

      Returns boolean