Skip to main content

OtpResource

The otp resource provides methods for creating, verifying, and managing one-time passwords for authentication flows.

new()

await contiguity.otp.new(params: OtpNewParams): Promise<{ otp_id: string }>
Generate and send a new one-time password to a phone number.
params
OtpNewParams
required
otp_id
string
Unique identifier for the OTP session. Use this to verify the code later.
const result = await contiguity.otp.new({
  to: '+1234567890',
  language: 'en',
  name: 'MyApp'
});

console.log(result.otp_id); // "otp_..."

verify()

await contiguity.otp.verify(params: OtpVerifyParams): Promise<{ verified: boolean }>
Verify an OTP code entered by the user.
params
OtpVerifyParams
required
verified
boolean
true if the OTP code is correct, false otherwise.
const result = await contiguity.otp.verify({
  otp_id: 'otp_...',
  otp: '123456'
});

if (result.verified) {
  console.log('OTP verified successfully!');
} else {
  console.log('Invalid OTP code.');
}

resend()

await contiguity.otp.resend(params: OtpResendParams): Promise<{ resent: boolean }>
Resend the OTP code to the same phone number.
params
OtpResendParams
required
resent
boolean
true if the OTP was successfully resent.
const result = await contiguity.otp.resend({
  otp_id: 'otp_...'
});

console.log(result.resent); // true

reverse.initiate()

await contiguity.otp.reverse.initiate(params: OtpReverseInitiateParams): Promise<any>
Initiate a reverse OTP flow where the user calls or texts a number to verify.
params
OtpReverseInitiateParams
required
const result = await contiguity.otp.reverse.initiate({
  number: '+1234567890',
  language: 'en',
  success_url: 'https://yourapp.com/verified'
});

console.log(result);

reverse.verify()

await contiguity.otp.reverse.verify(otp_id: string): Promise<any>
Check the verification status of a reverse OTP session.
otp_id
string
required
The reverse OTP session ID.
const status = await contiguity.otp.reverse.verify('otp_...');
console.log(status);

reverse.cancel()

await contiguity.otp.reverse.cancel(otp_id: string): Promise<any>
Cancel an ongoing reverse OTP session.
otp_id
string
required
The reverse OTP session ID to cancel.
await contiguity.otp.reverse.cancel('otp_...');

Complete Example

import { Contiguity } from 'contiguity';

const contiguity = new Contiguity('contiguity_sk_...');

// Step 1: Send OTP
const { otp_id } = await contiguity.otp.new({
  to: '+1234567890',
  language: 'en',
  name: 'MyApp'
});

// Step 2: User enters code, verify it
const userCode = '123456'; // From user input
const { verified } = await contiguity.otp.verify({
  otp_id,
  otp: userCode
});

if (verified) {
  // Proceed with authentication
  console.log('User verified!');
} else {
  // Show error or allow resend
  console.log('Invalid code');
}

// Step 3 (optional): Resend if needed
await contiguity.otp.resend({ otp_id });

Build docs developers (and LLMs) love