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.
Sessions authenticate users with the Incode API. Sessions must be created before rendering any SDK component.
Creating a Session
Use createSession() from @incodetech/core/session:
import { createSession } from '@incodetech/core/session';
import { setup } from '@incodetech/core';
// Create session (typically on your backend, or client-side for dev)
const session = await createSession('your-api-key', {
configurationId: 'your-config-id',
language: 'en-US',
});
// Setup SDK with the token
await setup({
apiURL: 'https://demo-api.incodesmile.com',
token: session.token,
});
Tip
Security note: Embedding your API key in client-side code is acceptable for development, but for production you should create the session on your backend and pass only the token to the frontend.
Server-Side Session Creation (Recommended for Production)
Create the session token on your backend, then pass it to the frontend:
Backend (Node.js example)
const response = await fetch('https://demo-api.incodesmile.com/omni/start', {
method: 'POST',
headers: {
'content-type': 'application/json',
'x-api-key': process.env.INCODE_API_KEY,
'api-version': '1.0',
},
body: JSON.stringify({
configurationId: 'your-config-id',
language: 'en-US',
}),
});
if (!response.ok) {
throw new Error(`Failed to create Incode session: ${response.status}`);
}
const { token } = await response.json();
// Send token to frontend
Frontend
import { setup } from '@incodetech/core';
import '@incodetech/web/flow';
import '@incodetech/web/flow/styles.css';
// Token received from your backend
await setup({
apiURL: 'https://demo-api.incodesmile.com',
token: sessionToken,
});
const flow = document.querySelector('incode-flow');
if (flow) {
flow.config = { token: sessionToken, lang: 'en-US' };
flow.onFinish = (result) => {
/* ... */
};
}
Continuing a Session from a Handoff Link
When a user moves from desktop to mobile, the mobile link carries a uuid (and, with QR phishing resistance, a url_uuid). Use continueSession() on the mobile page to continue that session instead of creating a new one:
import {
continueSession,
IncodeApiError,
refreshQrUrlUuid,
SESSION_CONTINUE_ERROR_CODES,
} from '@incodetech/core/session';
const params = new URLSearchParams(window.location.search);
const uuid = params.get('uuid') ?? '';
// Rotate the QR anti-phishing token first, when the link has one.
const urlUuid = await refreshQrUrlUuid({
urlUuid: params.get('url_uuid') ?? undefined,
onboardingId: uuid,
});
try {
const session = await continueSession('your-api-key', { uuid, urlUuid });
// Pass session.token to the flow, as in "Creating a Session".
} catch (error) {
if (
error instanceof IncodeApiError &&
error.status === SESSION_CONTINUE_ERROR_CODES.continuationLimitReached
) {
// The session has no continues left: show your own message.
}
}
createSession() with a uuid does the same, and so does <incode-flow> with apiKey, configurationId and uuid in its config.
The server allows a limited number of continues per session (two by default) within 48 hours of the session start. Each call spends one, and a reload of the mobile page is a new call. The SDK does not retry a refused continue.
A refused continue throws an IncodeApiError. Its status is one of SESSION_CONTINUE_ERROR_CODES:
status |
Key | Meaning |
|---|---|---|
4026 |
invalidUuid |
The link is unknown or expired. |
4081 |
invalidQrValidation |
The QR anti-phishing validation failed. |
4086 |
continuationPeriodExpired |
The 48-hour window to continue the session passed. |
4087 |
continuationLimitReached |
The session has no continues left. |
4088 |
sessionNotActive |
The session is no longer active. |
Session Lifecycle
- Sessions expire after a configured timeout (set in your dashboard)
- Each verification step updates the session state on the backend
- Create a new session for each new verification attempt
External ID Deprecated
Warning
externalId and interviewId are deprecated. To resume a desktop-to-mobile handoff, use continueSession().
You can still associate sessions with your own user identifiers by passing externalId to createSession():
import { createSession } from '@incodetech/core/session';
const session = await createSession('your-api-key', {
configurationId: 'your-config-id',
externalId: 'your-user-id-123',
});
This allows you to link Incode sessions to users in your system.
Getting the Finish Status
After a flow completes, retrieve the final verification result:
import { getFinishStatus } from '@incodetech/core/session';
const result = await getFinishStatus('YOUR_CONFIGURATION_ID');
// Or: await getFinishStatus(undefined) to omit the flow filter.
// Optional cancellation: getFinishStatus('YOUR_CONFIGURATION_ID', signal).
// result.action: 'approved' | 'rejected' | 'none'
// result.scoreStatus: 'OK' | 'WARN' | 'MANUAL_OK' | 'FAIL' | 'UNKNOWN' | 'MANUAL_FAIL'
// result.redirectionUrl: string
The first argument is required and accepts string | undefined | null; the second is an optional AbortSignal.
result.endScreenTitle and result.endScreenText are always null from this helper. The orchestrated Flow's onFinish result fills these nullable fields from Dashboard copy received at session creation. Use that callback result when rendering the configured completion text.
See Also
- Getting Started: Basic integration
- API Reference: Full API documentation
- IncodeFlow Component: Rendering the flow