NextJS - iProov/web GitHub Wiki
Integrating the iProov Web SDK with Next.js requires a dynamic import because the SDK accesses browser APIs (window, document) that are not available during server-side rendering.
âšī¸ Supported versions. We support any Next.js release still receiving security patches â that is Active or Maintenance LTS under the Next.js support policy, which at the time of writing is v15 and above. This guide uses the Pages Router.
The same dynamic import pattern works in the App Router, but the component must be a Client Component â add
"use client"at the top of the file, becauseuseEffectanduseStateare not available in a Server Component. Reaching fornext/dynamicwithssr: falseinstead will not help: Next.js rejects that option in Server Components.
The key difference from a standard React integration is that the SDK must be loaded dynamically inside a useEffect hook (or equivalent client-side lifecycle), not at the top of the file. It is loaded by URL, from a copy in public/, rather than imported from @iproov/web-sdk â see Serving the SDK.
pages/index.tsx
import Head from "next/head"
import { useEffect, useState } from "react"
import type IProovMe from "@iproov/web-sdk"
function IProov() {
const [token, setToken] = useState<string | null>(null)
const [isLoading, setLoading] = useState(true)
useEffect(() => {
const fetchToken = async () => {
const sdkUrl = new URL("/iproov/iProovMe.js", window.location.href).href
await import(/* webpackIgnore: true */ /* @vite-ignore */ sdkUrl)
// Replace with your backend token endpoint
const response = await fetch("***YOUR_BACKEND_TOKEN_ENDPOINT***", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
resource: "https://iproov.app",
user_id: "[email protected]",
client: "Web SDK NextJS",
}),
})
const data = await response.json()
setToken(data.token)
setLoading(false)
}
fetchToken().catch((err) => {
setLoading(false)
console.error(err)
})
}, [])
if (isLoading) return <p>Loading...</p>
if (!token) return <p>Error loading token</p>
return (
<iproov-me
token={token}
base_url="***YOUR_BASE_URL***"
assets_url="***YOUR_ASSETS_URL***"
aria_live="assertive"
>
<div slot="ready">
<div>Ready to verify</div>
</div>
</iproov-me>
)
}
export default function Home() {
return (
<>
<Head>
<title>iProov Web SDK - Next.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<main>
<IProov />
</main>
</>
)
}Next.js pre-renders pages on the server by default. The iProov Web SDK registers a custom element (<iproov-me>) and accesses browser-only APIs during initialisation, so it has to load client-side, inside useEffect, after the component has mounted.
It is loaded by URL because iProovMe.js must reach the browser exactly as published: if Next.js bundles or minifies it, every transaction fails. await import("@iproov/web-sdk") would hand the file to the bundler, while a URL held in a variable, with webpackIgnore, is left as a native import() by both webpack and Turbopack.
import type IProovMe from "@iproov/web-sdk" is removed at compile time, so it keeps the SDK's type declarations in the build without loading any of its code.
The Support Checker has its own subpath, so it can be loaded without pulling in the component at all â which is the point of it. Unlike iProovMe.js, it can go through the bundler. Import it dynamically for the same SSR reason:
useEffect(() => {
const init = async () => {
const { iProovSupport } = await import("@iproov/web-sdk/iProovSupport.js")
const supportChecker = new iProovSupport()
const { supported, granted } = await supportChecker.check()
console.log("Supported:", supported, "Granted:", granted)
}
init()
}, [])
â ī¸ From 7.0.0 thewindow.IProovglobal has been removed, sonew window.IProov.IProovSupport()no longer works. The.jsextension on the subpath is required, becauseexportssubpaths are matched exactly.
See the full Support Checker documentation.
Pass custom slots as children of the <iproov-me> component:
<iproov-me token={token} base_url="***YOUR_BASE_URL***" assets_url="***YOUR_ASSETS_URL***">
<div slot="ready">Ready to scan</div>
<div slot="button">Start scanning</div>
<div slot="passed">Verification passed!</div>
<div slot="failed">Verification failed</div>
</iproov-me>next.config.js
const nextConfig = {
reactStrictMode: true,
}
module.exports = nextConfigNo special Next.js configuration is required beyond the standard setup. The dynamic import handles the SSR/client boundary.
Next.js serves public/ as-is, in next dev and next build alike. Copy iProovMe.js there, with iproov-assets/ if you self-host the assets, before each dev server start and build:
scripts/copy-iproov.mjs
import { cpSync, rmSync } from "node:fs"
const sdk = "node_modules/@iproov/web-sdk"
const out = "public/iproov"
rmSync(out, { recursive: true, force: true })
cpSync(`${sdk}/iProovMe.js`, `${out}/iProovMe.js`)
cpSync(`${sdk}/iproov-assets`, `${out}/iproov-assets`, { recursive: true })package.json
{
"scripts": {
"dev": "node scripts/copy-iproov.mjs && next dev",
"build": "node scripts/copy-iproov.mjs && next build"
}
}Add public/iproov/ to .gitignore. Set assets_url to https://your.app.example/iproov/ to load the rest of the SDK from the copy, or leave it unset to load it from cdn.iproov.app and drop the script's iproov-assets line. See Loading the SDK for the full recipe.
The iProov SDK requires HTTPS for camera access. Next.js generates a locally trusted certificate for you:
next dev --experimental-httpsThe dev server then serves https://localhost:3000. To use your own certificate instead, pass --experimental-https-key and --experimental-https-cert.