SDK reference, Incode Web SDK 2 Reference / Customization 2

Event Callbacks

Warning

This guide is specific to Web SDK 2.x. For Web SDK 1.x, you can find documentation here.

Do not attempt to upgrade or implement without support. Contact your Incode representative to check if you are a candidate for this upgrade.

The SDK provides callbacks to integrate with your application's logic.

The snippets below show the callback shapes you'd assign to the element (e.g. flow.onFinish = ...) or set inside config. For full mounting examples (vanilla, React, Angular, Vue) see IncodeFlow Component and Framework Integration.

IncodeFlow Callbacks

onFinish

Called when the verification flow finishes. This is the primary callback you should set:

flow.onFinish = (result) => {
  console.log('Action:', result?.action); // 'approved' | 'rejected' | 'none'
  console.log('Status:', result?.scoreStatus); // 'OK' | 'WARN' | 'FAIL' | ...
  console.log('Redirect:', result?.redirectionUrl);

  if (result?.action === 'approved') {
    // Proceed with your flow
  }
};

result may be undefined (the signature is (result?: FinishStatus, meta?: IncodeFinishMeta) => void), so always null-check.

Knowing whether the SDK already drew a finish screen

onFinish receives an optional second argument. Read meta.sdkOwnsTerminalScreen to avoid stacking your own completion screen on top of one the SDK already rendered:

import type { IncodeFinishMeta } from '@incodetech/web/workflow';

workflow.onFinish = (result, meta) => {
  notifyBackend(result); // side effects always run

  if (!meta?.sdkOwnsTerminalScreen) {
    showMyCompletionScreen(result);
  }
};

It is true when the SDK has drawn its own terminal screen. Today, that means <incode-workflow> with the status-specific finish screen enabled. onFinish still fires either way, so side effects such as notifying a parent frame keep working.

The flag is advisory. The SDK cannot stop your page from rendering, so it only helps if you read it. Existing single-argument handlers keep working unchanged, and meta is undefined for modules that do not set it.

onError

Called when an error occurs. onError receives three arguments:

Argument Type Description
error string | undefined A message for your logs. The text can change between versions, so do not compare it in your code.
errorCode number | undefined The status of a request that failed: the Incode API status code (for example, 4028), or the HTTP status when the response has no Incode code.
moduleErrorCode string | undefined An optional stable code that identifies the cause. Use this value when your code must react to a specific error.

An argument is undefined when it does not apply to the error. For example, a camera denial is not a failed request, so errorCode is undefined.

flow.onError = (error, errorCode, moduleErrorCode) => {
  if (moduleErrorCode === 'CAMERA_PERMISSION_DENIED') {
    // The SDK shows how to allow the camera. Log it, or show your own help.
    return;
  }
  console.error('Verification error:', error, errorCode, moduleErrorCode);
};

Camera permission denied

When the browser blocks the camera, the SDK shows a screen that tells the user how to allow the camera again. When this screen appears, the SDK calls onError one time with moduleErrorCode set to CAMERA_PERMISSION_DENIED, and errorCode is undefined. The screen has a Refresh page button that reloads the page.

The user can continue only after they allow the camera and reload the page. To keep the SDK instructions visible, do not remove the element in this callback. To show your own screen, remove the element and show your screen.

This applies to <incode-flow>, <incode-workflow>, and these standalone elements: <incode-id>, <incode-selfie>, <incode-authentication>, <incode-video-selfie>, <incode-document-capture>, and <incode-fiscal-qr>.

User cancelled and no internet connection

Two more moduleErrorCode values report a decision by the user rather than a failure:

Code When it fires
USER_CANCELLED The user confirmed the close button (see Let the user cancel). error and errorCode are undefined.
NO_INTERNET_CONNECTION The user selected Close on the "No internet connection" screen, or a standalone module that you gave your own manager could not resume when the connection returned. error and errorCode are undefined.

While the device is offline, the SDK shows the "No internet connection" screen and does not call onError, onFinish, or onContinue. When the connection returns, the screen closes by itself and the current step starts again from its first screen. Attempts the step already used stay used.

When combined consent fails to load, moduleErrorCode is COMBINED_CONSENT_LOAD_FAILED. When mandatory or ML consent fails to load, it is REGULATORY_CONSENT_LOAD_FAILED. In both cases, error retains the diagnostic message while <incode-flow> and <incode-workflow> display localized generic error copy.

Terminal Mandatory Consent/ML Consent cancellation uses the flow's generic error presentation and error code. Do not match the former Mandatory consent error text; messages can vary. Headless errorModule(error?, moduleErrorCode?) also accepts an omitted message.

onModuleLoading / onModuleLoaded

Track lazy-loading of each module's UI chunk. These are config callbacks, not element callbacks:

flow.config = {
  token: session.token,
  onModuleLoading: (moduleKey) => setLoading(moduleKey),
  onModuleLoaded: (moduleKey) => setLoading(null),
};

onWasmWarmup

Called when ML models begin loading:

flow.config = {
  token: session.token,
  onWasmWarmup: (pipelines) => console.log('Loading ML models:', pipelines),
};

onFlowEvent

Subscribe to curated flow milestones. For raw analytics events such as screenOpened or elementClicked, use subscribeEvent from @incodetech/core/events instead.

flow.config = {
  token: session.token,
  onFlowEvent: (event) => console.log('Flow event:', event.type, event),
};

Branch on event.type. The FlowEvent union and its member types are exported from @incodetech/core/flow-events:

import type { FlowEvent } from '@incodetech/core/flow-events';

flow.config = {
  token: session.token,
  onFlowEvent: (event: FlowEvent) => {
    if (event.type === 'flow.module.started') {
      console.log(`Starting ${event.module}`);
    }
  },
};
event.type Type Additional fields
flow.started FlowStartedEvent –
flow.ready FlowReadyEvent payload: { flow, steps, currentStep?, currentStepIndex }
flow.module.started FlowModuleStartedEvent module, payload: { moduleIndex?, totalModules? }
flow.module.completed FlowModuleCompletedEvent module, payload: { moduleIndex?, totalModules? }
flow.completed FlowCompletedEvent payload?: the finish status
flow.error FlowErrorEvent error: the error message
flow.closed FlowClosedEvent –

Every event also carries timestamp (epoch milliseconds) and an optional interviewId. All events except flow.started also carry an optional flowId.

moduleIndex and totalModules count the home screen as module 0 when the flow shows one. totalModules is the length of the flow's current step list, so it can drop while the flow runs. If you show progress, read totalModules from each event rather than from the first one.

FlowEventListener types the callback itself, and FlowEventSubscribable types a manager that exposes this stream.

Headless flow events

Managers returned by createFlowManager, createOrchestratedFlowManager, and createWorkflowManager expose subscribeFlowEvent(listener). It uses the curated FlowEvent union above; raw analytics remain a separate subscribeEvent stream.

import type { FlowEventSubscribable } from '@incodetech/core/flow-events';

function observeFlow(manager: FlowEventSubscribable): () => void {
  return manager.subscribeFlowEvent((event) => {
    if (event.type === 'flow.module.started') {
      console.log('Starting', event.module);
    }
  });
}

Call the returned unsubscribe function when your observer unmounts. When your host owns the manager, also call manager.stop() on teardown to release its resources.

Individual Module Callbacks

The standalone module elements (<incode-phone>, <incode-selfie>, <incode-id>, …) follow the same property-assignment pattern.

onFinish

phone.onFinish = () => console.log('Phone verified!');

onError

selfie.onError = (error, errorCode, moduleErrorCode) =>
  console.error('Selfie error:', error, errorCode, moduleErrorCode);

The arguments are the same as for IncodeFlow onError. Modules that use the camera report a blocked camera with moduleErrorCode set to CAMERA_PERMISSION_DENIED. See Camera permission denied.

Finish Status

The onFinish callback on IncodeFlow receives a FinishStatus object:

import type { FinishStatus } from '@incodetech/core/flow';

// FinishStatus shape:
// {
//   redirectionUrl: string;
//   action: 'approved' | 'rejected' | 'none';
//   scoreStatus: 'OK' | 'WARN' | 'MANUAL_OK' | 'FAIL' | 'UNKNOWN' | 'MANUAL_FAIL';
//   endScreenTitle: string | null;
//   endScreenText: string | null;
// }

FinishStatus is also re-exported from @incodetech/core/session if you prefer that grouping.

Field Description
action Final verification decision
scoreStatus Detailed status from scoring
redirectionUrl Configured redirect URL (if any)
endScreenTitle Dashboard completion title, or null
endScreenText Dashboard completion text, or null

The orchestrated Flow obtains this copy from session creation. The raw getFinishStatus(flowId) helper returns null for both fields. Hosts should provide a display fallback when copy is absent.

Dashboard Events

For tracking events to the Incode dashboard (module opens, screen transitions, custom events), see Dashboard Events.

See Also

Was this page helpful?