Installation
npm install @veriff/incontext-sdk
Usage
Before initializing the InContext SDK
, you need a valid Veriff session URL. To create a session URL, you can use our JS SDK or our API.
import { createVeriffFrame } from '@veriff/incontext-sdk';
const { createVeriffFrame } = require('@veriff/incontext-sdk');
const veriffFrame = createVeriffFrame({ url: 'SESSION_URL' });
This will render an iframe with a modal that contains Veriff application.
Exposed types
import { EmbeddedOptions, MESSAGES, VeriffFrameOptions } from '@veriff/incontext-sdk';
Listening for events
Pass the onEvent
callback function when initializing SDK
import { createVeriffFrame, MESSAGES } from '@veriff/incontext-sdk';
createVeriffFrame({
url: 'SESSION_URL',
onEvent: function (msg: MESSAGES) {
switch (msg) {
case MESSAGES.STARTED:
console.log('Verification started');
break;
case MESSAGES.SUBMITTED:
console.log('Verification submitted');
break;
case MESSAGES.FINISHED:
console.log('Verification finished');
break;
case MESSAGES.CANCELED:
console.log('Verification closed');
break;
case MESSAGES.RELOAD_REQUEST:
console.log('Verification reloaded');
break;
}
},
});
Using with inline script
Include a script tag:
<script src="https://cdn.veriff.me/incontext/js/v2.1.0/veriff.js"></script>
window.veriffSDK.createVeriffFrame({ url: 'session url' });
Embedded mode
Before using embedded mode, make sure the incontext_sdk_embedded_allowed
feature flag is enabled for your account.
The embedded mode allows you to inject the Veriff flow to a specific part of your website, without a modal. To enable embedded mode, set the embedded
option to true
.
Note about dimensions
- Minimum 600x680 width/height
- Optimal 800x800 width/height
The flow will render regardless of the dimensions, but the user experience might be affected.
Example
const veriffFrame = createVeriffFrame({
url: 'SESSION_URL',
embedded: true,
embeddedOptions: {
rootElementID: 'embedded-container',
},
});
<div
style={{ width: '635px', height: '670px', border: '1px solid #ccc' }}
id="embedded-container"
/>
API
createVeriffFrame([options])
Create modal with Veriff application.
Returns an object that controls the modal.
.close()
Close Veriff modal. Normally modal will be closed due to user input, but if you want to control it(e.g. timeout), please use this function.
onReload
This is an edge case for Safari iOS to re-request camera permissions
Example:
const url = sessionStorage.getItem('@veriff-session-url') || getSessionUrl();
veriffSDK.createVeriffFrame({
url,
onReload: () => {
window.location.reload();
},
});