Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

Time-based one-time password (TOTP)

Methods

createTOTP()

function createTOTP(): Promise<TOTPResource>;

Generates a TOTP secret for a user that can be used to register the application on the user's authenticator app of choice. Note that if this method is called again (while still unverified), it replaces the previously generated secret.

Returns

TypeDescription
Promise<TOTPResource>The newly created TOTP object.

verifyTOTP()

function verifyTOTP(params: VerifyTOTPParams): Promise<TOTPResource>;

Verifies a TOTP secret after a user has created it. The user must provide a code from their authenticator app, that has been generated using the previously created secret. This way, correct set up and ownership of the authenticator app can be validated.

VerifyTOTPParams

NameTypeDescription
codestringA 6 digit TOTP generated from the user's authenticator app.

Returns

TypeDescription
Promise<TOTPResource>The newly verified TOTP object.

disableTOTP()

function disableTOTP(): Promise<DeletedObject>;

Disables TOTP by deleting the user's TOTP secret.

Returns

TypeDescription
Promise<DeletedObject>The reference to the deleted TOTP object.

createBackupCode()

function createBackupCode(): Promise<BackupCodeResource>;

Generates a fresh new set of backup codes for the user. Note that if this method is called again, it replaces the previously generated codes.

Returns

TypeDescription
Promise<BackupCodeResource>The newly created backup code.

Types

TOTPResource

NameTypeDescription
idstringA unique identifier for this TOTP secret
secret?stringThe generated TOTP secret. Note: this is only returned to the client upon creation and cannot be retrieved afterwards.
uri?stringA complete TOTP configuration URI including the Issuer, Account, etc that can be pasted to an authenticator app or encoded to a QR code and scanned for convenience. Just like the secret, the URI is exposed to the client only upon creation and cannot be retrieved afterwards.
verifiedbooleanWhether this TOTP secret has been verified by the user by providing one code generated with it. TOTP is not enabled on the user unless they have a verified secret.
backupCodes?string[]A set of fresh generated Backup codes. Note that this will be populated if the feature is enabled in your instance and the user doesn't already have backup codes generated.
createdAtDateCreation date of the TOTP secret
updatedAtDateUpdate timestamp of the TOTP secret

BackupCodeResource

NameTypeDescription
idstringA unique identifier for this TOTP secret
codesstring[]The generated set of backup codes
createdAtDateCreation date of the TOTP secret
updatedAtDateUpdate timestamp of the TOTP secret

Last updated on October 4, 2023

What did you think of this content?

Clerk © 2023