Web SDK Integration
The Prembly Web SDK opens a secure verification flow in a modal on your web page. It works with plain HTML and with any framework, including React, Next.js, Vue, Angular, and Svelte.
Web Integration Paths
| Integration | Best For | Package / Source |
|---|---|---|
| Workflow SDK (recommended) | Running a workflow you built in the dashboard | https://js.prembly.com/v1/inline/widget-v3.js |
| Identity widget script | Existing integrations that use a widget from SDK Setup | https://js.prembly.com/v1/inline/widget.js |
| React package | React and Next.js apps that use the identity widget through a hook | prembly-react-kyc |
The Workflow SDK uses your publishable key (test_pk_... or live_pk_...) and a workflow ID. The identity widget script and React package use the Widget key and Widget ID of a widget you create under SDK Setup.
1. Workflow SDK
Add the hosted script to your page, then call Prembly.workflow.start() from a button click or form submission. The SDK creates the session, opens the workflow in a modal, and calls your callback once when it ends.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prembly Workflow Demo</title>
</head>
<body>
<button id="verify-btn">Verify Identity</button>
<p id="status"></p>
<!-- Prembly hosted script -->
<script src="https://js.prembly.com/v1/inline/widget-v3.js"></script>
<script>
var flow = null; // lets you close the workflow from your own code
document.getElementById('verify-btn').onclick = function () {
Prembly.workflow.start({
publishableKey: 'test_pk_your_key_here', // public key only, never a secret key
workflowId: 'wf_your_workflow_id',
customer: {
firstName: 'Jane',
lastName: 'Doe',
email: 'jane@example.com',
phone: '08012345678', // optional
reference: 'usr_9921' // optional: your own ID for this customer
},
// Optional: an ID you already have, so they skip the ID screen (exactly one)
// prefill: { bvn: '22212345678' },
// Optional: every step the person goes through
onEvent: function (event) {
console.log('Workflow event:', event.type);
},
// Called once when the workflow ends
callback: function (result) {
flow = null;
var status = document.getElementById('status');
if (result.status === 'completed') {
status.textContent = 'Verification completed. Session: ' + result.sessionId;
} else if (result.status === 'manual_review') {
status.textContent = 'Submitted. We are reviewing your details.';
} else if (result.status === 'cancelled') {
status.textContent = 'Verification was closed before it finished.';
} else if (result.status === 'expired') {
status.textContent = 'The session expired. Please try again.';
} else if (result.error) {
// It could not start: bad key, wrong workflow ID, network problem
status.textContent = 'Could not start: ' + result.error.message;
} else {
status.textContent = 'Verification failed.';
}
}
}).then(function (handle) {
flow = handle;
});
};
// To close it from your page instead: if (flow) flow.close();
// The callback then gets status "cancelled".
</script>
</body>
</html>Publishable keys only
publishableKey must start with test_pk_ or live_pk_. The SDK refuses any other key before making a request. Never put a secret key (test_sk_ / live_sk_) in a web page.
Frameworks (React, Next.js, Vue, Angular, Svelte)
Load the script once, in your document head or index template (in Next.js, with next/script). Then call window.Prembly.workflow.start({...}) from a click handler or component method. Call it only in the browser, not during server rendering.
Options
| Option | Type | Required | Description |
|---|---|---|---|
publishableKey | String | Yes | Your public key, test_pk_... or live_pk_.... |
workflowId | String | Yes | The ID of the workflow to run. |
customer.firstName | String | Yes | The customer's first name. |
customer.lastName | String | Yes | The customer's last name. |
customer.email | String | Yes | The customer's email address. Must be a valid email. |
customer.phone | String | Optional | The customer's phone number. |
customer.reference | String | Optional | Your own ID for this customer. |
metadata | Object | Optional | Custom key-value pairs, returned in the session lookup and webhooks. |
prefill | Object | Optional | One ID number you already have, so the customer skips the ID screen: { bvn: '...' } or { nin: '...' }. See Prefill an ID number. |
onEvent | Function | Optional | Called for each step the customer goes through. See Events. |
collectDeviceData | Boolean | Optional | Defaults to true. Set false to stop the SDK sending a device ID. See Device data. |
callback | Function | Yes | Called once when the workflow ends or cannot start. See Results. |
Prembly.workflow.start() returns a promise that resolves to a handle with one method, close(). The promise resolves even when the workflow can't start. In that case the error goes to your callback, and the promise never rejects.
Results
callback receives one result object, exactly once.
result.status | When | Other fields |
|---|---|---|
completed | The customer finished the workflow. | sessionId |
manual_review | The customer finished, and the session needs review by your team. | sessionId |
failed | The workflow ended in failure. | sessionId |
failed | The workflow could not start. | error.code, error.message (no sessionId) |
expired | The session expired before the customer finished. | sessionId |
cancelled | The customer closed the modal, or you called handle.close(). | sessionId, and lastEvent (the last event type received, if any) |
Both kinds of failed share the same status, so check result.error to tell them apart, as the example above does.
Don't update your records from the callback alone. Use webhooks as the source of truth.
Errors
When the workflow can't start, result.error.code is one of:
error.code | Meaning |
|---|---|
invalid_key | publishableKey doesn't start with test_pk_ or live_pk_. |
invalid_request | A required option is missing or invalid (for example, a bad email, or prefill without exactly one ID), or Prembly rejected the request (HTTP 4xx). |
unauthorised | Prembly rejected the publishable key (HTTP 401 or 403). |
not_found | The workflow ID was not found (HTTP 404). |
rate_limited | Too many requests (HTTP 429). Wait, then retry. |
timeout | Creating the session took longer than 15 seconds. |
network_error | Prembly couldn't be reached, or the customer closed the modal before the session was created. |
server_error | Prembly returned an error or an incomplete response. Retry later. |
not_available | start() was called outside a browser, such as during server rendering. |
error.message is a readable description you can log or show.
Events
onEvent receives an object for each step:
| Field | Description |
|---|---|
type | The event name, such as a step starting or finishing. The last event is one of the result statuses: completed, failed, manual_review, expired, or cancelled. |
sessionId | The workflow session. |
nodeId | The workflow step the event belongs to, when it has one. |
Use onEvent for progress and analytics. Use callback to act on the result: it is the only function guaranteed to be called once.
Closing the workflow
The modal has a close button. To close it from your own code, keep the handle the promise resolves to and call handle.close(). The callback then receives cancelled. If you close the modal before the session is created, callback receives failed with the error code network_error instead.
Device data
By default, the SDK stores a random device ID in the browser (localStorage key prembly_tm_device_id, or a cookie of the same name if storage is blocked) and gives it to the verification page when that page asks for it. This helps Prembly recognise returning devices. Pass collectDeviceData: false to turn this off, for example until the customer accepts your cookie policy.
2. Identity Widget Script
Add the hosted widget script tag to your web page, then invoke IdentityKYC.verify() inside a button click handler or form submission event.
The hosted script takes your Widget key as merchant_key and your Widget ID as config_id. It does not accept widget_key or widget_id: passing those fails validation with merchant_key is required.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KYC Integration Demo</title>
</head>
<body>
<button onclick="verifyKYC()" class="btn btn-purple px-4 py-3">
Verify Identity
</button>
<div id="success-message" style="display: none;">
Verification completed successfully!
</div>
<!-- Prembly Hosted Web Script -->
<script src="https://js.prembly.com/v1/inline/widget.js"></script>
<script>
function verifyKYC() {
IdentityKYC.verify({
merchant_key: 'your_widget_key_here',
config_id: 'your_widget_id_here',
first_name: 'Jane',
last_name: 'Doe',
email: 'jane@example.com',
user_ref: 'usr_9921',
callback: function (response) {
console.log('Prembly verification response:', response);
if (response.status === 'success') {
document.getElementById('success-message').style.display = 'block';
return;
}
alert(response.message || 'Verification was not completed.');
}
});
}
</script>
</body>
</html>Framework Note (Vue, Angular, Svelte)
Load the script once in your document head or index template, then call window.IdentityKYC.verify({...}) inside your framework component methods or router actions.
IdentityKYC in widget-v3.js
widget-v3.js also defines IdentityKYC.verify(), but that copy takes widget_key and widget_id, like the React package, not merchant_key and config_id. If you switch the script URL, rename those two parameters too.
3. React Package Implementation (prembly-react-kyc)
Use the prembly-react-kyc package when building React or Next.js web applications that prefer a hook-based API (useIdentityPayKYC). The hook loads the hosted widget script for you, so don't add the <script> tag as well.
The hook takes your Widget key as widget_key and your Widget ID as widget_id.
To run a workflow from React, use the Workflow SDK instead: load widget-v3.js once and call window.Prembly.workflow.start() from your component.
Installation
npm install prembly-react-kyc
# or
yarn add prembly-react-kycReact 19 (including Next.js 15)
The package declares support for React 18 only, so npm install fails with an ERESOLVE error in a React 19 project. Install it with npm install prembly-react-kyc --legacy-peer-deps. React 19 is not officially supported yet.
Basic Component Example
In the Next.js App Router, the component that calls the hook must be a client component, so keep the 'use client'; line. Plain React and the Pages Router don't need it.
'use client';
import React from 'react';
import useIdentityPayKYC from 'prembly-react-kyc';
const VerificationButton = () => {
const config = {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
phone: '+2348012345678',
widget_key: 'your_widget_key_here',
widget_id: 'your_widget_id_here',
metadata: {
transaction_id: 'txn_123456',
user_id: 'usr_789'
},
callback: (response) => {
console.log('Verification result:', response);
if (response.status === 'success') {
alert('Verification completed!');
}
}
};
const verifyWithIdentity = useIdentityPayKYC(config);
return (
<button onClick={verifyWithIdentity} className="px-6 py-3 bg-blue-600 text-white rounded-lg">
Start Verification
</button>
);
};
export default VerificationButton;Identity Widget Parameter Reference
IdentityKYC.verify() and useIdentityPayKYC() take the same configuration object. Only the names of the key and ID differ:
| Parameter | Type | Required | Description |
|---|---|---|---|
merchant_key (script) / widget_key (React) | String | Yes | Your public Widget key from SDK Setup in the dashboard. |
config_id (script) / widget_id (React) | String | Yes | Your Widget ID from SDK Setup in the dashboard. |
first_name | String | Yes | The user's first name. |
last_name | String | Yes | The user's last name. |
email | String | Yes | The user's email address. Must be a valid email. |
phone | String | Optional | The user's phone number with country code. |
metadata | Object | Optional | Custom key-value pairs (e.g., { internal_id: "123" }) returned in callbacks, the session lookup, and webhooks. Can also carry a BVN or NIN to skip the ID screen — see Prefill an ID number. |
user_ref | String | Optional | Hosted script only. Your own reference for the user, stored as metadata.user_ref. With the React package, put it in metadata yourself. |
callback | Function | Yes | Called once when verification succeeds, fails, or is cancelled, or when the session cannot start. See Callback responses. |
Callback responses
The callback receives (response, data). data is the raw result on success and null otherwise.
response.code | response.status | When |
|---|---|---|
00 | success | Verification succeeded. response.data and response.channel carry the result. |
E01 | failed | Verification failed. response.message says why. |
E02 | cancelled | The user cancelled. |
E00 | — | The session did not start: a required parameter is missing or invalid, the key or ID was rejected, or the script could not load. response.message and response.data or response.errors give the detail. Usually no status; a script load failure in the React package sets failed. |
Check response.code, not only response.status: most E00 responses have no status.
Don't update your records from the callback alone. Use webhooks as the source of truth.
Web Troubleshooting & Common Issues
Prembly is not defined: Loadwidget-v3.js, notwidget.js, and wait for it to finish loading before callingPrembly.workflow.start().widget.jsonly definesIdentityKYC.invalid_keyfrom the Workflow SDK: You passed a Widget key or a secret key.publishableKeymust start withtest_pk_orlive_pk_.not_foundfrom the Workflow SDK: Check the workflow ID, and that it belongs to the same organisation as the publishable key.- Widget script not loading (identity widget): Ensure
https://js.prembly.com/v1/inline/widget.jshas completed loading prior to triggeringIdentityKYC.verify(). The React package loads the script itself and reports a load failure to your callback asE00. merchant_key is requiredwith the identity widget script: You passedwidget_key/widget_idtowidget.js. It takes them asmerchant_key/config_id.widget_key is requiredafter switching towidget-v3.js: TheIdentityKYCinwidget-v3.jstakeswidget_key/widget_id, notmerchant_key/config_id.- Invalid Configuration Error: Verify that your Widget key and Widget ID belong to the same widget, and match the active mode (Live vs Sandbox) selected in your dashboard.
- Camera Access Denied / Blocked: Modern web browsers block camera and media capture APIs on unencrypted connections. Ensure your website is served over HTTPS during testing and production deployment.