@veriff/incontext-sdk

In-Context Veriff browser integration

Usage no npm install needed!

<script type="module">
  import veriffIncontextSdk from 'https://cdn.skypack.dev/@veriff/incontext-sdk';
</script>

README

Installation

npm install @veriff/incontext-sdk

Usage

You need to have a Veriff session URL generated before initializing the SDK. Please, see our documentation to learn how to generate one.

// ES6
import { createVeriffFrame } from '@veriff/incontext-sdk';

// CommonJS
const { createVeriffFrame } = require('@veriff/incontext-sdk');

const veriffFrame = createVeriffFrame({ url: 'session url' })

This will render a modal with adapted Veriff application in iframe.

Listening for events

Pass onEvent callback function when initializing SDK

import { createVeriffFrame, MESSAGES } from '@veriff/incontext-sdk';

createVeriffFrame({
  url: 'session url',
  onEvent: function(msg) {
    switch(msg) {
      case MESSAGES.CANCELED:
        //
        break;
    }
  }
})
  • msg:
    • STARTED - session status changed to 'started'.
    • CANCELED - user closed the modal.
    • FINISHED - user finished verification flow.

Using with inline script

Include a script tag:

<script src='https://cdn.veriff.me/incontext/js/v1/veriff.js'></script>
window.veriffSDK.createVeriffFrame({ url: 'session url' });

API

createVeriffFrame([options])

Create modal with Veriff application.

  • [options] - Configuration object.
    • url - Veriff session URL
    • lang - Set user interface language
    • onEvent - Event callback function
    • onReload - Reload request callback - handle reloading the webpage and reopening the SDK

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 callback can be called on some browsers when a user has denied camera access and to re-request access the host page has to be reloaded. For best UX we recommend reloading the webpage & reopening the Veriff SDK automatically.

Example:

const url = sessionStorage.getItem('@veriff-session-url') || getSessionUrl()

veriffSDK.createVeriffFrame({
  url,
  onReload: () => {
    // Logic to re-open Veriff SDK after page reload
    // e.g. sessionStorage.setItem('@veriff-session-url', url);
    window.location.reload();
  },
});