Allow users to authenticate with their phone number and OTP (One-Time Password).

Prerequisites

  • You need to have the Dynamic Client initialized.
  • You need to have the phone number authentication method enabled in your environment’s settings in the Dynamic dashboard.

Usage

import {
  sendSmsOTP,
  verifyOTP
} from '@dynamic-labs-sdk/client';

// With the user's phone number, call sendSmsOTP to get the otpVerification
// Then, once the user inputs the OTP code, call verifyOTP to verify it and complete the authentication

let otpVerification = null

const singInWithPhone = async () => {
  // Replace 'US' with the user's country code and '1234567890' with the user's phone number
  otpVerification = await sendSmsOTP({ isoCountryCode: 'US', phoneNumber: '1234567890' });
  // Store the otpVerification for later use with the verifyOTP function
};

const verifyOTP = async () => {
  // Use the same otpVerification object that you got from the sendSmsOTP function
  // Replace '123456' with the OTP code entered by the user
  await verifyOTP({ otpVerification, otp: '123456' });
};