Skip to main content
Version: 1.0

2.1.2.1 Default UI

Overview

The VerifySpeed Web UI package provides a pre-built, customizable user interface for phone number verification in web applications. This approach offers:

  • Ready-to-use verification components for both Deep Link and OTP verification methods
  • Consistent UI across different frameworks with minimal integration effort
  • Full customization options for colors, themes, and styling
  • Responsive design that works seamlessly on both mobile and desktop devices
  • Automatic handling of QR code generation and Smart App Banner display based on user's device

With the Default UI, you can implement secure phone verification in minutes rather than building custom UI components from scratch. Simply install the package, configure your client key, and implement the necessary event handlers to connect with your backend.

Setup Guide for Web Integration

Step 1: Install the Package

Install the VerifySpeed Web UI package using npm:

npm install verifyspeed-web-ui

Step 2: Common Setup

The following setup is required across all frameworks:

1. Set Client Key

VerifySpeedUI.setClientKey('YOUR_CLIENT_KEY');

2. Event Handler Implementation

Implement these event handlers that will be used in your framework-specific code:

import { InitVerificationDetail, VerificationCompletedDetail } from 'verifyspeed-web-ui';

const handleInitVerification = async (event: CustomEvent<InitVerificationDetail>) => {
const { methodName, resolve, reject } = event.detail;
try {
const response = await fetch('YOUR_API_ENDPOINT', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ methodName }),
});

const data = await response.json();

resolve({
deepLink: data.deepLink,
verificationKey: data.verificationKey,
});
} catch (error) {
reject(error);
}
};

const handleVerificationCompleted = async (event: CustomEvent<VerificationCompletedDetail>) => {
try {
const { token } = event.detail;

await fetch('YOUR_VERIFICATION_ENDPOINT', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token }),
});
} catch (error) {
console.error('Verification failed:', error);
}
};

3. Configure UI (Optional)

VerifySpeedUI.setConfig({
darkMode: true,
qrCode: {
margin: 10,
image: 'https://i.ibb.co/kVB67QTD/Verify-Speed.png',
... // other options
},
smartAppBannerOptions: {
position: 'top',
theme: 'dark',
containerStyle: 'background-color: #000000; border-radius: 10px;',
closeButtonStyle: 'background-color: #000000; border-radius: 10px;',
... // other options
},
});

Step 3: Framework-Specific Implementation

After setting up the common configuration and handlers above, choose your framework below to implement the UI component:

TypeScript

React implementation using hooks (useEffect and useRef) for managing component lifecycle and references:

tip

Full example project can be found here

import { useEffect, useRef } from 'react';
import {
InitVerificationDetail,
VerificationCompletedDetail,
VerifySpeedUI,
VerifySpeedUIEvent
} from 'verifyspeed-web-ui';

function App() {
const verifySpeedRef = useRef<HTMLElement>(null);

useEffect(() => {
const element = verifySpeedRef.current;
if (element) {
element.addEventListener(
VerifySpeedUIEvent.INIT_VERIFICATION,
handleInitVerification as unknown as EventListener
);
element.addEventListener(
VerifySpeedUIEvent.VERIFICATION_COMPLETED,
handleVerificationCompleted as unknown as EventListener
);

return () => {
element.removeEventListener(
VerifySpeedUIEvent.INIT_VERIFICATION,
handleInitVerification as unknown as EventListener
);
element.removeEventListener(
VerifySpeedUIEvent.VERIFICATION_COMPLETED,
handleVerificationCompleted as unknown as EventListener
);
};
}
}, []);

return <verify-speed-ui ref={verifySpeedRef} />;
}
JavaScript

React implementation using hooks (useEffect and useRef) for managing component lifecycle and references:

tip

Full example project can be found here

import { useEffect, useRef } from 'react';
import { VerifySpeedUIEvent } from 'verifyspeed-web-ui';

function App() {
const verifySpeedRef = useRef(null);

useEffect(() => {
const element = verifySpeedRef.current;
if (element) {
element.addEventListener(
VerifySpeedUIEvent.INIT_VERIFICATION,
handleInitVerification
);
element.addEventListener(
VerifySpeedUIEvent.VERIFICATION_COMPLETED,
handleVerificationCompleted
);

return () => {
element.removeEventListener(
VerifySpeedUIEvent.INIT_VERIFICATION,
handleInitVerification
);
element.removeEventListener(
VerifySpeedUIEvent.VERIFICATION_COMPLETED,
handleVerificationCompleted
);
};
}
}, []);

return <verify-speed-ui ref={verifySpeedRef} />;
}
tip

In example projects, search for keywords TIP if you want to know how to implement Web Integration.

Remember to replace the following placeholders with your actual values:

  • 'YOUR_CLIENT_KEY': Your VerifySpeed client key
  • 'YOUR_API_ENDPOINT': Your backend endpoint for starting verification
  • 'YOUR_VERIFICATION_ENDPOINT': Your backend endpoint for completing verification