Introduction
The SebeVerify Web SDK is a hyper-lightweight, zero-dependency vanilla JavaScript SDK that lets merchants embed identity verification directly into their websites. It manages the desktop-to-mobile QR handoff so users can capture high-quality document scans and complete facial liveness checks from their phone.
The package is published as sebeverify-sdk and ships as ES modules, CommonJS, and a UMD browser build — use whichever fits your stack. TypeScript declarations are included.
Your API key stays on your server
apiKey option.Installation
Install the SDK with your preferred package manager:
# npm
npm install sebeverify-sdk
# yarn
yarn add sebeverify-sdk
# pnpm
pnpm add sebeverify-sdkCDN / no-build
If you aren't using a bundler, load the SDK from a CDN. The CDN build puts the SDK on window.SebeVerify. Call SebeVerify.default() to set it up.
You still need a server route to start the session. Here it is in Node with Express. Any server language works.
// server.js (Node + Express 5). Any server works: it only needs to
// call createVerificationSession() and return the result.
import express from "express";
import { createVerificationSession } from "sebeverify-sdk";
const app = express();
// requireLogin is your own auth middleware
app.post("/api/verification-session", requireLogin, async (req, res) => {
const session = await createVerificationSession({
apiKey: process.env.SEBEVERIFY_API_KEY, // secret: server only
projectId: process.env.SEBEVERIFY_PROJECT_ID,
backendUrl: "https://api.sebeverify.com",
documentType: "passport", // or "national-id"
});
await saveVerificationSession(req.user.id, session.sessionId);
res.json(session);
});<script src="https://unpkg.com/sebeverify-sdk@0.2.0/dist/index.global.js"></script>
<script>
// The CDN build puts the SDK on window.SebeVerify.
// The setup function is SebeVerify.default.
const verifier = SebeVerify.default({
projectId: "your-project-uuid",
redirectUrl: "https://yourdomain.com/verify/complete",
});
document.getElementById("verify-btn")
.addEventListener("click", async () => {
// Ask your server for a session, then open the flow with it
const res = await fetch("/api/verification-session", { method: "POST" });
const session = await res.json();
await verifier.start(session);
});
</script>Quick Start
You'll need an API key and a Project ID from the SebeVerify dashboard. The API key is secret. Only your server uses it.
1. On your server: start a session
Put your keys in server-only environment variables:
# .env (server only)
SEBEVERIFY_API_KEY=your_secret_api_key
SEBEVERIFY_PROJECT_ID=your-project-uuid
# Never name these NEXT_PUBLIC_...
# That prefix copies the value into the browser bundle.Then add a route that calls createVerificationSession(). Never call it from browser code: it needs your secret API key.
// app/api/verification-session/route.ts (Next.js), or any server route
import { createVerificationSession } from "sebeverify-sdk";
export async function POST(request: Request) {
// 1. Only signed-in users may start a session. Use your own auth here.
const user = await getCurrentUser(request);
if (!user) return new Response("Unauthorized", { status: 401 });
// 2. Start a session. Your API key never leaves your server.
const session = await createVerificationSession({
apiKey: process.env.SEBEVERIFY_API_KEY!, // secret: server only
projectId: process.env.SEBEVERIFY_PROJECT_ID!,
backendUrl: "https://api.sebeverify.com",
documentType: "national-id", // or "passport"
});
// 3. Save the session ID with the user, so you can match the webhook later.
await db.users.update({
where: { id: user.id },
data: { verificationSessionId: session.sessionId },
});
// 4. Send the session to the browser. It holds no secrets.
return Response.json(session);
}2. In the browser: open the flow
Ask your route for a session, then pass it to start(session).
import SebeVerify from "sebeverify-sdk";
// 1. Set up the SDK. There is no API key here: it stays on your server.
const verifier = SebeVerify({
projectId: "your-project-uuid",
redirectUrl: "https://yourdomain.com/verify/complete",
});
// 2. Listen for events
verifier.on("started", () => console.log("Flow started"));
verifier.on("mobile_opened", () => console.log("Redirected to mobile flow"));
verifier.on("cancelled", () => console.log("User cancelled"));
verifier.on("error", (err) => console.error("Verification error:", err));
// 3. On click, ask your server for a session, then open the flow with it
document
.getElementById("verify-btn")
?.addEventListener("click", async () => {
try {
const res = await fetch("/api/verification-session", { method: "POST" });
if (!res.ok) throw new Error("Could not start verification");
const session = await res.json();
await verifier.start(session);
} catch (err) {
console.error(err);
}
});Tip
expiresAt.How it works
The SDK is a thin, browser-side orchestration layer. It never handles biometric data itself — that all flows through the SebeVerify hosted web app, which the SDK either embeds in a modal (desktop) or hands off to (mobile).
Start a session
Your server calls createVerificationSession() with your secret API key. It gets back a session ID, a short-lived client token, and the document type.
Handoff
Your browser code calls verifier.start(session). On desktop, a modal opens. On mobile, the browser navigates straight to the hosted flow.
Capture
The hosted web app guides the user through document scan, selfie, and a 60fps on-device liveness challenge. It uploads with the client token, never your API key.
Result
Once processed, the user is redirected to your redirectUrl, and your webhook fires with the final verification result.
SebeVerifyConfig
The single argument to SebeVerify(). All fields except webAppUrl are required and validated synchronously — bad input throws immediately so misconfigurations surface during development.
// Browser: the argument to SebeVerify()
interface SebeVerifyConfig {
/** Your project's UUID, from the dashboard. Not a secret. */
projectId: string;
/** Absolute http(s) URL the user is sent to after verification finishes. */
redirectUrl: string;
/** Override the hosted web app URL (only for self-host / staging / local). */
webAppUrl?: string;
}| Field | Type | Description |
|---|---|---|
| projectIdrequired | string | UUID identifying the project the verification belongs to. Visible in the dashboard project settings. Not a secret. |
| redirectUrlrequired | string | Absolute http(s) URL the user lands on after the flow completes. Validated at construction; non-URLs and non-http(s) protocols throw. |
| webAppUrl | string | Override the SebeVerify-hosted web app. Defaults to https://sebe-verify-sdk.vercel.app. Only set this for self-host, staging, or local dev. |
No apiKey option
apiKey option; version 0.2.0 removed it. If your API key ever reached a browser, revoke it in the dashboard and make a new one.Session types
Your server creates a session with createVerificationSession(). Your browser code passes the result to start(session). The result holds no secrets, so you can send all of it to the browser.
type VerificationDocumentType = "national-id" | "passport";
// Server: the argument to createVerificationSession()
interface CreateVerificationSessionOptions {
/** Your secret API key. Keep it on your server. */
apiKey: string;
projectId: string;
/** SebeVerify API base URL, e.g. "https://api.sebeverify.com". */
backendUrl: string;
/** Fixed for the whole session. Default: "national-id". */
documentType?: VerificationDocumentType;
}
// Server: what createVerificationSession() returns.
// Holds no secrets, so it is safe to send to the browser.
interface CreateVerificationSessionResult extends VerificationSessionHandle {
/** When the session and its client token stop working (ISO date). */
expiresAt: string;
backendUrl: string;
projectId: string;
}
// Browser: what start() needs. Pass the whole result from your server.
interface VerificationSessionHandle {
sessionId: string;
/** Short-lived token for this one session. */
clientToken: string;
/** The user can't pick another document type. */
documentType: VerificationDocumentType;
}| Field | Type | Description |
|---|---|---|
| sessionId | string | The session ID. The webhook uses the same ID, so save it with your user. |
| clientToken | string | Short-lived token for this one session. Safe to give to the browser. It does not work for any other session. |
| documentType | "national-id" | "passport" | Fixed for the session. The hosted page only offers this document, and the user can't pick another one. |
| expiresAt | string | When the session and its client token stop working (ISO date). After that, start a new session. |
SebeVerifyResult
The shape passed to your event callbacks when the SDK has payload to share.
interface SebeVerifyResult {
sessionId: string;
status: "submitted" | "failed" | "cancelled" | "pending";
submissionData?: {
documentType: string;
submittedAt: string; // ISO 8601
message: string;
};
requestId?: string;
}Note
status as advisory only.createVerificationSession(options)
Server only. Starts a verification session for one end user. It calls the SebeVerify API with your secret API key and returns the session for the browser. Call it once per verification, from a route that only signed-in users can reach.
function createVerificationSession(
options: CreateVerificationSessionOptions,
): Promise<CreateVerificationSessionResult>;It throws if apiKey, projectId or backendUrl is missing, or if the API refuses the request. If it runs in a browser it logs a warning, because that means your API key is in browser code.
SebeVerify(config)
The default export. Returns a new SebeVerifySDK instance bound to the config you pass. Throws synchronously on missing or malformed fields.
function SebeVerify(config: SebeVerifyConfig): SebeVerifySDK;.start(session)
Launches the verification flow for a session your server created with createVerificationSession(). Pass the whole result. On desktop browsers, opens a modal containing a CTA into the hosted web app. On mobile, navigates the current tab directly to the hosted flow.
start(session: VerificationSessionHandle): Promise<void>;Behaviour summary:
- Checks the session first. A missing session,
sessionIdorclientToken, or an unknowndocumentType, throws. - Then emits
started. - On mobile, sets
window.location.hrefand emitsmobile_opened. - On desktop, mounts an overlay modal at
document.body. Closing it (Esc, backdrop, Cancel) emitscancelled. - Any thrown error is re-emitted via
errorand rethrown from the promise.
.on(event, callback) / .off(event, callback)
Subscribe to lifecycle events. on() is chainable and returns the SDK instance.
on(event: EventType, callback: EventCallback): SebeVerifySDK;
off(event: EventType, callback: EventCallback): SebeVerifySDK;
type EventType = "started" | "mobile_opened" | "error" | "cancelled";
type EventCallback = (data?: SebeVerifyResult | Error) => void;Listeners are stored per event name in insertion order. Throwing inside a callback is caught and logged — it will not break subsequent listeners.
.destroy()
Closes the modal if open, removes all event listeners, and clears the internal session. Call this on component unmount in React / Vue / Svelte to avoid leaks.
destroy(): void;Event reference
The SDK emits a small, well-defined set of lifecycle events. You don't need to handle all of them — pick the ones that matter for your UX.
| Field | Type | Description |
|---|---|---|
| started | () => void | Fired when start(session) accepts the session, before the flow opens. Use it to disable your Verify button or show a loading state. |
| mobile_opened | () => void | Mobile only. Fired right before the browser navigates to the hosted flow. Use it to persist pre-redirect state. |
| cancelled | () => void | Desktop only. Fired when the user closes the modal via Esc, backdrop click, or the Cancel button. |
| error | (err: Error) => void | Fired for any thrown error during start(session), such as a missing session. The callback receives an Error instance. |
verifier
.on("started", () => {
// Fired when start(session) accepts the session, before the flow opens.
// Use this to disable your "Verify" button.
})
.on("mobile_opened", () => {
// Fired only on mobile devices, right before window.location is replaced
// by the hosted verification flow. Use to persist any pre-redirect state.
})
.on("cancelled", () => {
// Fired when the user closes the desktop modal (X, backdrop click, Esc).
// Re-enable your "Verify" button so the user can retry.
})
.on("error", (err) => {
// Fired for any error in start(session), such as a missing session.
// `err` is an Error instance.
showToast(err instanceof Error ? err.message : "Verification failed");
});React / Next.js
Two files. A server route starts the session with your API key. A client component asks that route for a session, opens the flow, and tears down on unmount.
// app/api/verification-session/route.ts (Next.js), or any server route
import { createVerificationSession } from "sebeverify-sdk";
export async function POST(request: Request) {
// 1. Only signed-in users may start a session. Use your own auth here.
const user = await getCurrentUser(request);
if (!user) return new Response("Unauthorized", { status: 401 });
// 2. Start a session. Your API key never leaves your server.
const session = await createVerificationSession({
apiKey: process.env.SEBEVERIFY_API_KEY!, // secret: server only
projectId: process.env.SEBEVERIFY_PROJECT_ID!,
backendUrl: "https://api.sebeverify.com",
documentType: "national-id", // or "passport"
});
// 3. Save the session ID with the user, so you can match the webhook later.
await db.users.update({
where: { id: user.id },
data: { verificationSessionId: session.sessionId },
});
// 4. Send the session to the browser. It holds no secrets.
return Response.json(session);
}"use client";
import { useEffect, useRef, useState } from "react";
import SebeVerify, { type SebeVerifySDK } from "sebeverify-sdk";
// Your project ID is not a secret. Your API key is, so it is not here:
// only the server route uses it.
const PROJECT_ID = "your-project-uuid";
export function VerifyButton() {
const verifier = useRef<SebeVerifySDK | null>(null);
const [busy, setBusy] = useState(false);
useEffect(() => {
verifier.current = SebeVerify({
projectId: PROJECT_ID,
redirectUrl: `${window.location.origin}/verify/complete`,
});
verifier.current.on("cancelled", () => setBusy(false));
return () => verifier.current?.destroy();
}, []);
async function handleClick() {
setBusy(true);
try {
// Ask your server route for a new session, then open the flow with it
const res = await fetch("/api/verification-session", { method: "POST" });
if (!res.ok) throw new Error("Could not start verification");
const session = await res.json();
await verifier.current?.start(session);
} catch (err) {
console.error(err);
setBusy(false);
}
}
return (
<button
type="button"
onClick={handleClick}
disabled={busy}
className="px-4 py-2 bg-primary text-white"
>
Verify identity
</button>
);
}Webhook handler
The webhook is the authoritative source of truth for verification results. Register your endpoint in the dashboard under Project → Webhooks.
// pages/api/webhooks/sebeverify.ts
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method !== "POST") return res.status(405).end();
const event = req.body as {
type: "verification.completed" | "verification.failed";
data: { session_id: string; status: string; document?: any };
};
if (event.type === "verification.completed" && event.data.status === "verified") {
await db.users.update({
where: { verificationSessionId: event.data.session_id },
data: { kycStatus: "verified" },
});
}
return res.status(200).json({ received: true });
}Security best practices
- Keep your API key on your server. Only createVerificationSession() uses it, and only on your server. Store it in a server-only environment variable. In Next.js, never give it the NEXT_PUBLIC_ prefix: that copies it into the browser bundle. If a key ever reached a browser, revoke it and make a new one.
- Protect your session route. Only signed-in users should be able to call the route that starts a session. Otherwise anyone could start sessions on your account.
- One session per verification. The client token works for one session only and expires at expiresAt. Start a new session each time a user begins verification. Don't share one between users.
- Always use HTTPS. The SDK validates that redirectUrl is http(s). In production, both your origin and your redirectUrl must be HTTPS — camera permissions require a secure context.
- Trust the webhook, not the client. The cancelled / mobile_opened events tell you about UI state, not verification outcome. Always reconcile final status from your backend webhook record.
- Scope keys per environment. Use separate projects (and therefore separate keys) for sandbox and production. Rotate keys immediately if one is leaked — rotation is one click in the dashboard.
Troubleshooting
“redirectUrl must be an absolute http(s) URL”+
You passed a relative path or a non-http protocol. Pass a full URL like https://yourdomain.com/verify/complete.
Modal doesn’t appear on desktop+
The SDK appends the overlay to document.body. If your app sets pointer-events: none or a higher z-index on a global overlay, the modal can render but be invisible or unclickable. Inspect for a <div role="dialog"> at the bottom of <body>.
Mobile redirect doesn’t fire+
Listen for the error event: start(session) emits it if the session is missing or incomplete. Also check that your session route returns status 200 and the full createVerificationSession() result.
“start() needs a session” / “session.clientToken is required”+
You called start() without a session, or passed only part of it. Fetch a session from your server route and pass the whole object to start(session).
“apiKey is required” on your server+
createVerificationSession() could not find your API key. Check that SEBEVERIFY_API_KEY is set in your server environment. Don't add the NEXT_PUBLIC_ prefix: the key must never reach the browser.
Uploads fail after the user waited a long time+
The session expired. A session and its client token stop working at expiresAt. Start a new session and call start(session) again.
Camera permission prompt is missing on the hosted flow+
Camera APIs require a secure context. Localhost works in dev, but staging/production must be HTTPS.
FAQ
Does the SDK store any biometric data?+
No. The SDK is a thin orchestration layer. All biometric capture happens inside the SebeVerify hosted web app, which transmits encrypted data directly to our backend.
Can I customise the modal?+
The desktop modal is intentionally minimal — title, CTA, cancel. For deeper customisation, embed the QR/CTA flow in your own UI instead of calling start(session). Custom themes for the hosted web app are on the roadmap.
What browsers are supported?+
Evergreen Chrome, Edge, Firefox, Safari, and their mobile equivalents. The hosted flow requires getUserMedia and a secure context.
Is there a React-specific wrapper?+
Not yet — the vanilla SDK works in every framework, and the React example above is ~20 lines. A first-party @sebeverify/react wrapper is planned.
What happens if the user closes the tab mid-flow?+
The session stays alive on the backend and can be resumed via the same URL until it expires. The user’s status will sit at pending until they finish or the session times out.
Ready to ship verification?
Spin up a sandbox project, grab your keys, and have a working integration in under an hour.