React
A ready-made button and a hook, from @myidii/react.
npm install @myidii/react@myidii/react is built on @myidii/web and installs it for you.
Button
LivenessButton fetches a session url from your server, runs the scan, and reports back. It renders a plain
<button>, so style it with your own className.
import { LivenessButton } from "@myidii/react";
export function VerifyStep() {
return (
<LivenessButton
className="btn btn-primary"
getUrl={async () => {
const res = await fetch("/api/start-check", { method: "POST" });
return (await res.json()).url;
}}
onResult={(r) => {
if (r.status === "passed") router.push("/onboarding/next");
}}
>
Verify it's me
</LivenessButton>
);
}Prop
Type
While the scan runs, the button is disabled and has aria-busy="true".
Hook
For your own UI, use useLiveness:
import { useLiveness } from "@myidii/react";
const { start, running, result } = useLiveness();
<button disabled={running} onClick={async () => start(await getUrlFromYourServer())}>
{running ? "Checking…" : "Verify it's me"}
</button>As with every browser result, confirm the verdict on your server before acting on it.