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
| Capacitor | 8 or later |
| iOS | 15 or later |
| Android | 7.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 syncRun 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:
CAMERAandRECORD_AUDIO, asked for only when a verification step needs them.ACCESS_NETWORK_STATEandDETECT_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
| Option | Type | Required | Description |
|---|---|---|---|
widgetKey | string | Yes | Your public Widget key from SDK Setup in the dashboard. |
widgetId | string | Yes | Your Widget ID from SDK Setup in the dashboard. |
firstName | string | Yes | The user's first name. |
lastName | string | Yes | The user's last name. |
email | string | Yes | The user's email address. |
phone | string | Optional | The user's phone number. |
metadata | object | Optional | Custom key-value pairs returned in callbacks, the session lookup, and webhooks. |
collectDeviceData | boolean | Optional | Defaults 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. |
callback | function | Yes | Receives 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.
status | Ends the flow | When | Other keys |
|---|---|---|---|
success | Yes | Verification finished. | data: the session payload. |
closed | Yes | The user closed the widget, or you called handle.close(). | — |
error | Yes | The widget reported an error, or could not open. | message |
api_error | Yes | Prembly rejected the session, for example a missing field or a wrong key or ID. The widget does not open. | message |
network_error | Yes | The session request could not reach Prembly. The widget does not open. | message |
not_available | Yes | Called outside the iOS or Android app. | message |
unknown_payload | No | The 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
| Option | Type | Required | Description |
|---|---|---|---|
publishableKey | string | Yes | Your publishable key: live_pk_... or test_pk_.... A secret key is refused. Never put a secret key in an app. |
workflowId | string | Yes | The workflow to run (wf_...), from your workflows list in the dashboard. |
customer | object | Yes | The person going through the workflow: firstName, lastName, email (required), phone, reference (your own reference for them). |
callback | function | Yes | Called once when the flow ends. See Workflow results. |
prefill | object | Optional | A BVN or NIN you already have. The customer skips the ID screen. See Prefill an ID number. |
metadata | object | Optional | Your own data, stored with the run. |
redirectUrl | string | Optional | Where to send the customer when the workflow finishes. |
collectDeviceData | boolean | Optional | Defaults 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. |
onEvent | function | Optional | Called 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:
status | Meaning |
|---|---|
completed | The workflow finished. |
failed | The 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_review | The workflow ended and is waiting for a reviewer. |
expired | The session expired before the customer finished. |
cancelled | The 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()callscallbackwithstatus: 'not_available'.PremblyWorkflow.start()callscallbackwithstatus: 'failed'anderror.codenot_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 syncafter 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
NSCameraUsageDescriptionandNSMicrophoneUsageDescriptionare present inInfo.plist. iOS terminates applications immediately if camera access is requested without a description string. api_errorbefore anything opens: Check thatfirstName,lastNameandemailare set, and that your Widget key and Widget ID belong to the same widget.