Skip to content

otplib API Documentation / @otplib/core / OTPToken

Type Alias: OTPToken

OTPToken = Brand<string, "OTPToken">

Defined in: packages/core/src/utility-types.ts:63

Branded string type for OTP tokens

Use this type to distinguish OTP tokens from regular strings at compile time, preventing accidental misuse.

Example

ts
import type { OTPToken } from '@otplib/core';

function validateToken(token: OTPToken): boolean {
  // TypeScript ensures only OTPToken values are passed
}

const token = await generate() as OTPToken;
validateToken(token); // OK
validateToken('123456'); // Type error

Released under the MIT License.