Overview

Capsule SDK provides support for phone number-based authentication, leveraging the Twilio API to enable a seamless login experience for your users. This feature allows you to implement a robust authentication system that links user wallets with unique phone number identifiers, preventing duplicate wallet creation across different login sessions.

To use phone number logins, ensure you’re using @usecapsule-web-sdk@1.13.0+ and @usecapsule/react-sdk@3.7.0+ or later versions.

Integration Methods

Capsule SDK offers two primary methods for integrating phone number logins:

  1. Using the pre-built Capsule Modal
  2. Implementing a custom UI with manual control

Method 1: Capsule Modal

For a quick and easy integration, you can use the CapsuleModal component. This pre-built solution handles the entire login flow, including phone number input and verification.

The disablePhoneLogin prop is false by default, enabling phone authentication. Set it to true if you wish to exclude this feature from the modal.

Method 2: Custom UI Implementation

For developers who prefer more control over the authentication process or need to implement a custom UI, you can use the following guide to create your own phone number login and setup flows.

Beta Testing Phone Numbers During beta testing, you can use any US phone number (+1) in the format (area code)-555-xxxx (like (425)-555-1234). Any OTP code will work for verification with these test phone numbers. These credentials are for beta testing only. You can delete test users anytime in the beta developer console to free up user slots.

// Function to handle phone number submission
const handleSubmitPhone = async (phone, countryCode) => {
  await capsule.logout();

  let userExists = false;

  userExists = await capsule.checkIfUserExistsByPhone(phone, countryCode);

  if (userExists) {
    const webAuthUrlForLogin = await capsule.initiateUserLoginForPhone(phone, countryCode);
    setWebAuthURLForLogin(webAuthUrlForLogin);
    return;
  }

  await capsule.createUserByPhone(phone, countryCode);
};

// Function to verify phone number with the received code
const handleVerifyPhone = async (code) => {
  const url = await capsule.verifyPhone(code);
  // Proceed with biometric creation/login as usual
};

This implementation provides granular control over the login process:

  1. The handleSubmitPhone function manages phone number submission, checking if the user exists, and initiating the appropriate login or user creation flow.
  2. The handleVerifyPhone function handles the verification of the phone number using the received code.

Need Assistance?

If you encounter any issues or need further clarification, don’t hesitate to reach out to our support team at support@usecapsule.com. We’re here to help you integrate Capsule SDK successfully into your application.