React - iProov/web GitHub Wiki
Integrating with React uses functional components and hooks. Install the @iproov/web-sdk package, serve its iProovMe.js from your application exactly as published, and render the <iproov-me> web component with your generated token.
âšī¸ Supported versions. We support any React version still receiving security patches. React publishes no support policy and patches only the latest major â see React versions â so in practice that is React 19 and above.
For Next.js integration, see the dedicated Next.js guide which covers the dynamic import pattern required for SSR frameworks.
The example below uses Vite with React 19. It loads the SDK by URL from a copy in public/ rather than importing @iproov/web-sdk â see Serving the SDK.
import { useCallback, useEffect, useState } from "react"
import { iProovSupport } from "@iproov/web-sdk/iProovSupport.js"
const SDK_URL = new URL("/iproov/iProovMe.js", window.location.href).href
function IProovMe() {
const [token, setToken] = useState(null)
const [isLoading, setLoading] = useState(true)
const [supported, setSupported] = useState(false)
const [hasCheckedSupport, setHasCheckedSupport] = useState(false)
const [supportChecker, setSupportChecker] = useState(null)
// Initialise SDK and fetch token
useEffect(() => {
const init = async () => {
await import(/* webpackIgnore: true */ /* @vite-ignore */ SDK_URL)
const supportChecker = new iProovSupport()
setSupportChecker(supportChecker)
// 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 React",
}),
})
const data = await response.json()
setToken(data.token)
setLoading(false)
}
init().catch((err) => {
setLoading(false)
console.error(err)
})
}, [])
// iOS motion permission must be triggered by a user gesture.
// React's synthetic events don't always satisfy this requirement,
// so we handle it explicitly via a button click.
const requestMotionPermission = useCallback(() => {
if (typeof DeviceMotionEvent.requestPermission === "function") {
return DeviceMotionEvent.requestPermission()
}
return Promise.resolve("granted")
}, [])
const checkSupport = useCallback(async () => {
if (supportChecker) {
const { supported, granted } = await supportChecker.checkWithPermission()
setHasCheckedSupport(true)
setSupported(supported)
console.log("Support:", supported, "Granted:", granted)
}
}, [supportChecker])
const handleClick = useCallback(() => {
requestMotionPermission().then((permissionState) => {
if (permissionState === "granted") {
checkSupport()
}
})
}, [requestMotionPermission, checkSupport])
if (isLoading) return <p>Loading...</p>
if (!token) return <p>Error loading token</p>
return (
<div>
<button onClick={handleClick}>Check Support</button>
<iproov-me
token={token}
base_url="***YOUR_BASE_URL***"
assets_url="***YOUR_ASSETS_URL***"
>
{/* Add any custom slots here */}
<div slot="button">
<button type="button">My Custom Button Text</button>
</div>
</iproov-me>
{hasCheckedSupport && (
supported ? <p>Device supported</p> : <p>Device not supported</p>
)}
</div>
)
}
export default IProovMeDeviceMotionEvent.requestPermission() must be called synchronously inside the click handler, before any await. iOS and iPadOS bind the prompt to the user gesture, and awaiting anything first spends the activation, after which the call is rejected with no prompt shown. React's onClick is fine for this â the example above calls requestPermission() first and only then awaits the result.
The Support Checker has its own subpath, so it can be imported without loading the component:
import { iProovSupport } from "@iproov/web-sdk/iProovSupport.js"
const supportChecker = new iProovSupport()
// Basic check (no permission prompt)
const { supported, granted, is_native_bridge } = await supportChecker.check()
// Check with permission prompt
const result = await supportChecker.checkWithPermission()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>iProovMe.js must reach the browser exactly as published: if a bundler such as Vite bundles, pre-bundles or minifies it, every transaction fails. That is why the example loads it by URL instead of importing @iproov/web-sdk. The Support Checker is not affected, and stays a normal import.
Copy iProovMe.js, with iproov-assets/ if you self-host the assets, into a folder your build serves as-is, before each dev server start and build. With Vite, that is public/:
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 && vite",
"build": "node scripts/copy-iproov.mjs && vite build"
}
}- Add
public/iproov/to.gitignore. - Keep
SDK_URLabsolute, as in the example: Vite's dev server refuses a root-relative import of a file inpublic/. - Set
assets_urltohttps://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'siproov-assetsline. - In TypeScript,
import type IProovMe from "@iproov/web-sdk"keeps the SDK's type declarations; it is removed at compile time.
See Loading the SDK for the full recipe, including webpack.