Skip to navigation

Web SDK (React)

The Web SDK is a drop-in React component that renders the full verification UI (ID selection, document scan, and active liveness) and calls the verification API for you. It uses a publishable (pk_) key and detects the environment automatically from the key prefix (pk_test_* → sandbox, pk_live_* → production). For shared concepts (supported countries, branding, results, and errors), see Client SDKs.

Install

pnpm add @toden/react
yarn add @toden/react
npm install @toden/react

Each key goes to its own host: pk_test_ keys to https://sandbox-api.toden.co and pk_live_ keys to https://api.toden.co. If your Content Security Policy or proxy allowlists the SDK’s traffic, allow both.

Upgrading from the earlier package

@toden/react 4.0.0 is the first release under this name. Before it, the SDK was published as @myazahq/kyc-sdk-react, which receives no further releases.

  1. Remove @myazahq/kyc-sdk-react and install @toden/react.
  2. Change your imports to @toden/react and @toden/react/styles.css. The API is unchanged, and the earlier names (MyazaKYC, useMyazaKYC, KYCError and the rest) still work as deprecated aliases.
  3. Two capture defaults changed in 4.0.0. The document review screen is off unless a workflow or the documentReview prop turns it on (uploaded photos are still always reviewed), and a document is photographed only once all four of its corners are in view.

Usage

<Verification /> renders a “Verify Identity” button plus the full modal flow. The trigger is a real <button>: pass children to relabel it, className to restyle it, or any other button attribute (disabled, type, aria-*, …). See Customising the trigger button. Import the bundled stylesheet once, anywhere in your app.

Build the flow once in the dashboard as a workflow, then mount it by id. The country, ID types, capture steps, branding and copy all come from the workflow, so changing the flow is a re-publish rather than a redeploy.

"use client";
import { Verification } from "@toden/react";
import "@toden/react/styles.css";
export default function VerifyButton() {
return (
<Verification
apiKey="pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
workflowId="wf_AbC123dEf456"
// Runtime data. A workflow is a shared template and cannot carry any of it.
userId="user_42"
userData={{ firstName: "Jane", lastName: "Doe", email: "jane@example.com" }}
metadata={{ requestId: "order_1001" }}
onSubmit={(submission) => console.log("submitted", submission.verificationId)}
onError={(err) => console.error(err)}
onClose={() => console.log("closed")}
/>
);
}

userData is worth passing. It is the name you believe the user has, and it is compared against the name read off their document, and that comparison is what produces dataMatch on the verification. Leave it out and the check simply never runs: there is nothing to compare the document against, and dataMatch comes back null.

Pass email when you hold it. The flow never asks for it. It is the address your organisation can have the applicant emailed at about a decision, and it lets a returning person use an address they saved.

It cannot live on the workflow. userId, userData and metadata are per-user runtime values, and a workflow is a template shared by every visitor, so these stay in code even when everything else moves to the dashboard.

Or configure everything in code

Skip the workflow and pass the flow’s shape as props. Useful for a quick start or a single fixed flow; anything you’d change later means a redeploy.

"use client";
import { Verification } from "@toden/react";
import "@toden/react/styles.css";
export default function VerifyButton() {
return (
<Verification
apiKey="pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
country="NG"
idTypes={["bvn", "drivers-license", "passport"]}
userData={{ firstName: "Jane", lastName: "Doe", email: "jane@example.com" }}
enableSelfie
enableDocumentCapture
enableLiveness
showThemeToggle
appearance={{ primaryColor: "#5645F5", companyName: "Acme", logo: "default", theme: "light" }}
consent={{ title: "Welcome, {firstName}", description: "A quick check to confirm it's really you." }}
success={{ title: "You're all set, {firstName}!", description: "We'll email you once your verification is reviewed." }}
metadata={{ requestId: "order_1001", userId: "user_42" }}
onSubmit={(submission) => {
// The verification was created; status is always 'pending'.
// Reconcile the final result on your backend via webhook or a secret-key
// GET /verifications/:id call (never from the client).
console.log("submitted", submission.verificationId);
}}
onError={(err) => console.error(err)}
onClose={() => console.log("closed")}
/>
);
}

Handling the result

Check with your backend before showing the flow, then give each ending its own screen. Handling results explains why.

"use client";
import { useRef } from "react";
import { Verification } from "@toden/react";
import "@toden/react/styles.css";
// `status` comes from your backend: "pending" while a verification it saved from
// onSubmit has no result yet, "approved" when GET /entities/:externalUserId says
// APPROVED, otherwise "not_started".
export function VerifyStep({ status, onPending, onStart, onRetry }) {
const submitted = useRef(false);
if (status === "approved") return <VerifiedBanner />;
if (status === "pending") return <PendingBanner />;
return (
<Verification
apiKey="pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
workflowId="wf_AbC123dEf456"
userId="user_42"
onSubmit={(submission) => {
submitted.current = true;
// Save the id on your backend: it marks this person as pending until the webhook.
onPending(submission.verificationId);
}}
onError={(err) => onRetry(err.message)}
onClose={() => {
// Closed before submitting: nothing to wait for, so go back to the start.
if (!submitted.current) onStart();
}}
/>
);
}

Props

PropTypeDefaultDescription
apiKeystringNoneRequired. Sent as Authorization: Bearer. The environment is derived from the key prefix (pk_test_* → sandbox, pk_live_* → production); an unrecognised prefix throws.
workflowIdstringNoneRun a published workflow (wf_…) built in the dashboard. The SDK fetches its configuration and uses it as the source of truth: workflow config wins over overlapping props. Makes country optional. Every @toden/react release supports it. See Configure with a workflow.
country'NG' | 'GH' | 'KE' | 'ZA' | 'CI' | stringNoneRequired unless workflowId is set. Country whose ID types are offered. Any ISO-2 country works: the org’s grants are enforced server-side. On a workflow that offers several countries, it is the person’s country: the country picker opens on it, listed first (4.4.0 and later). A country the workflow does not offer is ignored.
lockCountrybooleanfalseWith country, on a workflow that offers several countries: the flow uses that country and shows no country picker. Ignored when no country is passed or the workflow does not offer it. 4.4.0 and later.
livenessMode'gestures' | 'flash' | 'both' | 'passive''gestures'How the liveness step proves presence: 3D Active Motion (randomised gestures, always including a head turn), 3D Flash Check (the screen-flash sequence), Dual Check (3D Active Motion and 3D Flash Check in one run), or Passive Liveness (the person holds still and a liveness model checks the capture). Usually set by a workflow.
deviceIntelligencebooleantrueCollect device + IP fraud signals (Device Intelligence).
countriesArray<{ country, idTypes? }>NoneMulti-region. List more than one country and the flow opens with a country-select step; the picked country’s idTypes win. Usually set by a workflow.
idTypesIdType[]all enabled for orgSubset of ID types to offer; must be valid for country.
userData{ firstName?, lastName?, dateOfBirth?, email?, phone? }NonePre-fills the user’s details; fields provided here aren’t asked again. email fills the email verification step and is the address your organisation can have the applicant emailed at about a decision. phone (phoneNumber in Flutter) is in international format, such as +2348012345678, and fills the phone verification step. The applicant can change either before verifying it.
enableSelfiebooleantrueCapture a selfie during liveness.
enableDocumentCapturebooleantrueEnable the document-scan step for document IDs.
allowDocumentUploadbooleantrueAllow picking a document photo from the device (gallery / drag-and-drop) instead of the camera. false hides every “upload instead” affordance, except on the camera-permission-denied screen, where it stays as an escape hatch.
allowDocumentScanbooleantrueAllow scanning the document with the live camera. false never opens the camera for documents: the applicant uploads a photo of each side instead. Keep at least one of allowDocumentScan and allowDocumentUpload on; with both false the camera stays on. Usually set by a workflow.
documentReviewbooleanfalseShow the review screen (Retake and Continue) after a document scan. Off, a scan moves straight on. Uploaded photos always get it, and so does a scan that failed to upload or that the capture check could not read.
documentAudiobooleanfalseRecord sound on the document capture video. The consent screen says so. If the microphone is refused or unavailable the clip records without sound and the verification continues. In an iframe, allow it: allow="camera; microphone".
enableLivenessbooleantrueRun the liveness challenge step. The server can still disable it per ID type.
livenessAudiobooleanfalseRecord sound on the liveness recording. The consent screen says so. If the microphone is refused or unavailable the clip records without sound and the verification continues. In an iframe, allow it: allow="camera; microphone".
livenessGestureSet'directions' | 'classic''classic'Which gestures the liveness camera asks for in 3D Active Motion and Dual Check. directions: head turns and looks up or down, always with at least one turn, in an order picked for the session (how many: livenessDirectionCount). Each is said, written and shown on screen, and going the wrong way never fails the check. classic: two or three of nod, turn, blink and smile. Usually set in the workflow builder, where new workflows start on directions.
livenessDirectionCount2 | 3 | 43How many head directions the camera asks for with livenessGestureSet: 'directions'. Every check includes at least one head turn, left or right; the rest are picked at random. Fewer is quicker, more is harder to fake. Usually set in the workflow builder.
voiceGuidanceboolean | { enabled?, language?, voice?, localVoice?, localVoiceNeighbours? }trueSpoken liveness instructions (accessibility, audio output, no microphone). false mutes it; { language: 'fr-FR' } sets the language. From 4.4.0 the prompts are spoken in a Toden voice from the country of the document being verified, else a neighbouring country’s, else the workflow’s voice, else an American voice. localVoice: 'female' | 'male' | 'any' | 'off' (default 'any') picks the gender or turns matching off; localVoiceNeighbours: false skips neighbours; voice: 'device' uses the device’s own voice for everyone. Each key overrides the workflow’s.
selfieReviewbooleanfalseShow the selfie with Retake and Continue after the liveness capture. Off by default: the capture hands straight on to the next step. A selfie that fails to upload still shows it. Usually set by a workflow.
showThemeTogglebooleantrueShow a light/dark toggle inside the modal header. Set false to hide it; the flow then stays on appearance.theme and the user can’t switch it.
fullScreenbooleanfalseForce the flow to render full screen on every device (desktop drops the centred modal; the expand/collapse control is hidden).
disableClosebooleanfalseHide the close (X) button and block all user dismissal (backdrop click, Escape, mobile swipe-down). The flow can then only be closed programmatically via the useVerification() hook’s close(). The terminal “Submitted” step is non-dismissible regardless.
deviceHandoffbooleantrueOn desktop, show a “continue on your phone” screen (QR code + copyable link) before the flow starts, useful when the computer has no webcam. The user can still continue on the current device; when they finish on their phone, the desktop completes automatically and fires onSubmit. Set false to disable. No effect on mobile/touch devices.
consentStepbooleantrueShow the consent (welcome) screen as the first step. Set false when your own app has already asked for the person’s consent, and the flow opens straight on its first real step (the contact codes, the country picker, the ID list, the business form, or a scoped flow’s own check). Usually set by a workflow (the Consent step’s switch). Switching the screen off does not change what your organisation attests to Toden.
biometricBiometricFlowConfigsee Biometric re-authenticationThe biometric scopes’ flow options: selfieReview, resultDelivery ('both' | 'app' | 'webhook'), doneButton and copy (your own words on the face check screens, see below). Usually set by a workflow (the Presence Intelligence panel’s Flow section); ignored off the biometric scopes.
appearanceVerificationAppearancebrand defaultsBrand & theme the modal: colours, logo, light/dark. See Branding & theming.
consentVerificationConsentContentbuilt-in copyOverride the consent/welcome screen title and description. See Consent screen copy.
successVerificationSuccessContentbuilt-in copyOverride the success/submitted screen title and description. See Success screen copy.
metadataRecord<string, string>NoneForwarded with the verify request (include your requestId).
onStart() => voidNoneCalled when the flow opens.
onStepChange(step: VerificationStep) => voidNoneCalled on each step transition.
onSubmit(submission: VerificationSubmission) => voidNoneCalled when the server accepts the verification. status is always 'pending'.
onResult(result: VerificationResult) => voidNoneCalled once with the verdict on a flow that waits for it in the app (a biometric re-authentication on the default delivery). Never on a timeout. See Biometric re-authentication.
onClose() => voidNoneCalled when the user closes the flow.
onError(error: VerificationError) => voidNoneCalled for technical errors only; receives a typed VerificationError (a real Error with a code). Verification outcomes never come through here. See Errors.
childrenReactNodeVerify IdentityTrigger button label/content. Defaults to Verify with {companyName} when companyName is set, else Verify Identity.
classNamestringNoneTrigger button classes. Merged via tailwind-merge, so your classes override the built-in styling.
other button attrsButtonHTMLAttributesNoneAny standard <button> attribute (disabled, type, aria-*, style, …) is forwarded. onClick is reserved by the SDK.

The liveness camera

The liveness camera takes the whole dialog while it is live, on desktop and on a phone: the face sits in a tall window, the rest of the picture is blurred, and the instruction is shown above the window. There is nothing to configure.

The step downloads its face tracking files when it opens. They are tried in order: your own host at <assetsBasePath>/face-mesh/ when you set assetsBasePath, then the Toden server, then a public CDN. If your site has a Content Security Policy, allow the Toden server in script-src and connect-src, and add 'wasm-unsafe-eval' to script-src: the face tracking runs as WebAssembly. Files from the Toden server do not need 'unsafe-eval'. Files from the public CDN do, so a policy that blocks the Toden server stops the step from loading. A Toden voice is fetched from the Toden server too, so connect-src already covers it.

Document capture

The capture steps need no configuration:

  • A full-screen camera on phones. One top row holds back, the document and the side; an instruction shows what the camera needs; Upload, the shutter and Light sit along the bottom. The desktop camera uses the same controls.
  • Cut-off documents. When the capture check finds that the document runs off the photo, the person is asked to retake it, with no “Continue anyway”: the verification would fail a cut-off document (document_cut_off). For a face or barcode the check could not read, “Continue anyway” stays. From 4.4.0.
  • Sharper photos for the barcode. From 4.4.0 the camera asks a capable phone for 2560 by 1440 and keeps the photo at up to 2600 pixels, compressed once, so a card’s barcode can be read from it.
  • A recording long enough to check. From 4.4.0 no photo of a side is taken until its recording has run about two seconds, so the server can compare the two. The back’s recording starts as the card is turned over, so the person does not wait.
  • The cropper. Rotate turns the photo a quarter at a time, a NIN slip gets an upright box on phones, and on phones the cropper opens full screen. Its button reads “Use photo”.
  • “Take a photo” uses the SDK’s own camera on desktop as well as phones, for proof of address, supporting documents and the entrance photo.
  • Country and ID on one step. The person picks the country and the ID on the same screen.

Biometric re-authentication

A workflow on the biometric-authentication scope confirms it is really your user, matching a live selfie against the face you enrolled. Three options on the workflow, plus your own words for its screens, shape how the flow behaves, on the web exactly as on the mobile SDKs. All three live on the workflow’s Presence Intelligence panel in the builder, under Flow, so they need no code change; a prop-configured mount can pass the same biometric block.

  • Where the verdict lands: In the app and on your webhook (the default) keeps the person on one loading screen from the moment the selfie is taken until the check settles, polling the status endpoint for up to a minute, then shows whether it was them; your app hears the verdict in onResult and your webhook receives it as on every other flow. In the app only is the same wait, but the server sends no webhook for that check at all (verification.started and the terminal events included), so the verdict is your app’s alone. Webhook only shows the ordinary submitted screen and leaves the verdict to your webhook. Enrolment workflows record the reference and have no verdict to deliver, so they never wait.
  • Selfie review: whether the captured selfie is shown back with Retake and Continue before it is sent. Off by default on the biometric scopes: a face check is a few seconds long, and a review screen is a stop in the middle of it. Turn it on when you want the person to approve the photo first.
  • Done button: whether the final screen carries a Done button. On by default. Turn it off when your app closes the flow itself from onResult (or from onSubmit on a webhook delivery); the screen then stays until your app dismisses the SDK. A hosted page has no host app, so its redirect or close-this-tab note is unaffected.
  • Screen copy: your own title and description for the screens the person sees, on the workflow’s Presence Intelligence panel under Face check screens: the loading screen while the check runs (“Checking it’s you”) and, on a verdict delivered in the app, the verified screen (“You’re verified”) and the not-verified screen (“We couldn’t confirm it’s you”). Leave a field empty to keep the default; {firstName} and {lastName} fill from the userData you pass, as on the welcome and success screens. A not-verified description replaces the reason the server sends. Enrolment offers the loading screen only. In code the same block is biometric.copy (waiting, verified, declined, each with title and description).

When the flow waits, the SDK fires a callback with the verdict:

<Verification
apiKey="pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
workflowId="wf_AbC123dEf456" // a biometric-authentication workflow
userId="user_42" // required: the enrolled user being re-authenticated
onSubmit={(s) => console.log("submitted", s.verificationId)}
onResult={(r) => {
// r.status is the same vocabulary GET /api/v1/status/:id serves:
// 'approved' | 'declined' | 'in_review' | 'error' | ...
if (r.status === "approved") unlockSensitiveAction();
}}
>
Confirm it is you
</Verification>

onSubmit still fires the moment the check is submitted. onResult fires once when the wait settles, never when it times out, and carries the state and reason pair only; scores and other result data stay behind your secret key. Treat it as a courtesy to your UI: the webhook (where the flow sends one) and GET /api/v1/verifications/:id remain the record, and a decision your app enforces should rest on those, not on a value a client reported. HostedVerification accepts the same onResult for a minted re-authentication session opened on the hosted page.

Configure with a workflow

See Usage for the mount. The workflow’s configuration wins over any overlapping props, so the country, ID types, capture steps, branding, and copy all come from the dashboard. Only runtime data (userId, userData, metadata, and your callbacks) stays in code, because a workflow is a shared template and per-user values would leak between visitors.

A workflow is also the recommended way to turn on the extra capture steps: contact OTP (emailVerification / phoneVerification), proof of address (proofOfAddress), NFC chip (nfc), questionnaire, and business (KYB) verification (subjectType: 'business' + business), and to attach server-side decisioning. These are accepted as SDK props too, but configuring them on the workflow means you compose the checks once and change them by re-publishing, with no redeploy. See Workflows.

Customising the trigger button

<Verification /> renders a real <button>. In addition to the config props above it accepts standard button attributes (the props type is exported as VerificationProps), so you can treat it like any other button:

<Verification
{...config}
className="w-full rounded-full bg-black px-6 text-white"
disabled={!ready}
>
Start verification
</Verification>
  • children sets the label (falls back to Verify with {companyName} / Verify Identity).
  • className is merged through tailwind-merge, so your classes win over the defaults.
  • style is merged on top of the SDK’s injected theme variables, so theming still applies.
  • onClick is owned by the SDK (it opens the modal) and can’t be overridden. For a fully custom trigger element, use the useVerification() hook below.

Programmatic control

For a custom trigger instead of the built-in button, wrap your tree in VerificationProvider and drive the flow with the useVerification() hook:

import { VerificationProvider, useVerification } from "@toden/react";
function Trigger() {
const { open, close, isOpen, currentStep } = useVerification({
apiKey: "pk_test_…",
country: "NG",
onSubmit: (s) => console.log(s.verificationId),
});
return <button onClick={open} disabled={isOpen}>Verify ({currentStep ?? "idle"})</button>;
}
export default () => (
<VerificationProvider>
<Trigger />
</VerificationProvider>
);

The flow advances through VerificationStep values, reported via onStepChange / currentStep. The core path is consent → id-type → (id-input for number-only IDs, or document-capture) → liveness → submitted. Steps enabled by a workflow slot in automatically: email-verification / phone-verification (right after consent), country-select (multi-region), proof-of-address, questionnaire, and the KYB steps (business-details, business-key-people, business-documents, applicant-role).