Ionic (Capacitor) SDK Guide

The prembly-capacitor-kyc plugin runs Prembly's identity verification widget and your compliance workflows inside Ionic and Capacitor apps, whether you build with Angular, React, Vue, or plain JavaScript. The verification pages open in a native full-screen view, and the plugin passes the phone's real device ID and details to them.


Requirements

Capacitor8 or later
iOS15 or later
Android7.0 or later (API 24)

The plugin works only inside the iOS and Android apps. In a browser build, both entry points report not_available instead of opening. See Running in a browser.


Installation

npm install prembly-capacitor-kyc
npx cap sync

Run npx cap sync again whenever you update the plugin.


Native Permissions Setup

iOS Configuration (ios/App/App/Info.plist)

Add the camera and microphone usage descriptions. iOS shows them when a verification step needs the camera or microphone:

<key>NSCameraUsageDescription</key>
<string>The camera is used to verify your identity.</string>
<key>NSMicrophoneUsageDescription</key>
<string>The microphone is used for the liveness check.</string>

Android Configuration

Nothing to add. The plugin's manifest brings the permissions it needs:

  • CAMERA and RECORD_AUDIO, asked for only when a verification step needs them.
  • ACCESS_NETWORK_STATE and DETECT_SCREEN_RECORDING (Android 15 and later), which show no prompt.

It also declares a short, fixed list of packages under <queries> to detect remote-access apps and root managers. It does not use QUERY_ALL_PACKAGES. Google Play asks you to justify package visibility; the reason is fraud prevention.


Identity Verification Widget (PremblyIdentityKyc)

Call PremblyIdentityKyc.open() with your Widget key and Widget ID from SDK Setup in the dashboard:

import { PremblyIdentityKyc } from 'prembly-capacitor-kyc';

async function verifyIdentity() {
  const handle = await PremblyIdentityKyc.open({
    widgetKey: 'your_widget_key_here',
    widgetId: 'your_widget_id_here',
    firstName: 'Ada',
    lastName: 'Obi',
    email: 'ada@example.com',
    metadata: { user_id: 'usr_123' },
    callback: (response) => {
      console.log('Prembly:', response.status);
      if (response.status === 'success') {
        // Verification finished. Confirm the outcome from your backend.
      }
    },
  });

  // handle.close() dismisses the widget early. The callback then receives `closed`.
}

open() resolves once the widget is on screen, or straight away if it could not start. The outcome always arrives through callback.

PremblyIdentityKyc.open() Options

OptionTypeRequiredDescription
widgetKeystringYesYour public Widget key from SDK Setup in the dashboard.
widgetIdstringYesYour Widget ID from SDK Setup in the dashboard.
firstNamestringYesThe user's first name.
lastNamestringYesThe user's last name.
emailstringYesThe user's email address.
phonestringOptionalThe user's phone number.
metadataobjectOptionalCustom key-value pairs returned in callbacks, the session lookup, and webhooks.
collectDeviceDatabooleanOptionalDefaults to true. Reads the phone's own device ID and details and passes them to the widget, so device checks see the real device. No permission prompt is shown and location is never read. Set to false to use only what the web page can see.
callbackfunctionYesReceives an object with a status key. See Widget callback statuses.

TypeScript accepts the call without firstName, lastName and email, but Prembly rejects a session without them: the callback receives api_error.

Widget callback statuses

The widget closes itself when the flow ends. The ending statuses are reported once.

statusEnds the flowWhenOther keys
successYesVerification finished.data: the session payload.
closedYesThe user closed the widget, or you called handle.close().—
errorYesThe widget reported an error, or could not open.message
api_errorYesPrembly rejected the session, for example a missing field or a wrong key or ID. The widget does not open.message
network_errorYesThe session request could not reach Prembly. The widget does not open.message
not_availableYesCalled outside the iOS or Android app.message
unknown_payloadNoThe widget sent a message with no event name.data

Any other event the widget reports arrives with its own name as status, plus data, and the flow stays open.

Don't update your records from callback alone. Use webhooks as the source of truth.

Face comparison

To compare the user's selfie against a photo you already hold, turn on Face comparison in the widget's settings in the dashboard, then pass the image as compare_image inside metadata. Without the Face comparison setting, compare_image is ignored.

await PremblyIdentityKyc.open({
  widgetKey: 'your_widget_key_here',
  widgetId: 'your_widget_id_here',
  firstName: 'Ada',
  lastName: 'Obi',
  email: 'ada@example.com',
  metadata: {
    user_id: 'usr_123',
    compare_image: 'https://your-server.com/path-to-reference-image.jpg', // Or Base64 string
  },
  callback: (response) => console.log('Prembly:', response.status),
});

Run a Workflow (PremblyWorkflow)

PremblyWorkflow.start() runs one of your compliance workflows in the app. It uses your workflow ID and publishable key instead of a widget key and widget ID.

import { PremblyWorkflow } from 'prembly-capacitor-kyc';

async function startOnboarding() {
  const handle = await PremblyWorkflow.start({
    publishableKey: 'test_pk_...',
    workflowId: 'wf_123',
    customer: { firstName: 'Ada', lastName: 'Obi', email: 'ada@example.com' },
    metadata: { user_id: 'usr_123' },
    // Optional: a BVN or NIN you already have, so they skip the ID screen
    prefill: { bvn: '22212345678' },
    callback: (result) => {
      console.log('Workflow ended:', result.status);
    },
  });

  // handle.close() dismisses the workflow early. The callback then receives `cancelled`.
}

The camera and microphone are asked for only when a step needs them. The workflow screen closes itself when the workflow ends.

PremblyWorkflow.start() Options

OptionTypeRequiredDescription
publishableKeystringYesYour publishable key: live_pk_... or test_pk_.... A secret key is refused. Never put a secret key in an app.
workflowIdstringYesThe workflow to run (wf_...), from your workflows list in the dashboard.
customerobjectYesThe person going through the workflow: firstName, lastName, email (required), phone, reference (your own reference for them).
callbackfunctionYesCalled once when the flow ends. See Workflow results.
prefillobjectOptionalA BVN or NIN you already have. The customer skips the ID screen. See Prefill an ID number.
metadataobjectOptionalYour own data, stored with the run.
redirectUrlstringOptionalWhere to send the customer when the workflow finishes.
collectDeviceDatabooleanOptionalDefaults to true. Passes the phone's device ID and details to the workflow, so its device checks see the real device. No permission prompt is shown.
onEventfunctionOptionalCalled for every event the workflow reports, with type, sessionId and nodeId. Contains no personal data.

Workflow results

callback receives an object with status and, once a session exists, sessionId:

statusMeaning
completedThe workflow finished.
failedThe workflow ended in failure. If it could not start at all, there is no sessionId and error.code and error.message say why: invalid_key, invalid_request, unauthorised, not_found, rate_limited, server_error, network_error, timeout or not_available.
manual_reviewThe workflow ended and is waiting for a reviewer.
expiredThe session expired before the customer finished.
cancelledThe customer closed the flow before it ended, or you called handle.close(). lastEvent is the last event seen; processing means they finished their steps and the checks continue in the background.

As with the widget, use webhooks for the final outcome.


Running in a Browser

The plugin needs the native iOS or Android app. When your Ionic app runs in a browser, for example with ionic serve:

  • PremblyIdentityKyc.open() calls callback with status: 'not_available'.
  • PremblyWorkflow.start() calls callback with status: 'failed' and error.code not_available.

Nothing opens and nothing is thrown. Test verification on a device or emulator. For web users, use the Web SDK instead.


Troubleshooting (Capacitor)

  • Plugin not found, or the widget never opens on a device: Run npx cap sync after installing or updating the plugin, then rebuild the native app.
  • Callback receives not_available: The app is running in a browser. See Running in a browser.
  • Camera Crash on iOS: Confirm that NSCameraUsageDescription and NSMicrophoneUsageDescription are present in Info.plist. iOS terminates applications immediately if camera access is requested without a description string.
  • api_error before anything opens: Check that firstName, lastName and email are set, and that your Widget key and Widget ID belong to the same widget.