"use client"; import { useCallback, useEffect, useState } from "react"; import { listDevices, makeDeviceLink, removeDevice } from "@/lib/biolock/use-biolock"; import { enrolledHere } from "@/lib/biolock/use-biolock"; type Device = Awaited>[number]; const when = (seconds: number) => new Date(seconds * 1000).toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" }); // The devices that can sign in to this account with BioLock, and one-time links to add another. export function Devices() { const [devices, setDevices] = useState(null); const [link, setLink] = useState(null); const [message, setMessage] = useState(null); const here = typeof window === "undefined" ? [] : enrolledHere(); const load = useCallback(() => { listDevices().then(setDevices).catch((error: Error) => setMessage(error.message)); }, []); useEffect(load, [load]); const add = async () => { setMessage(null); try { const { url } = await makeDeviceLink(); setLink(url); } catch (error) { setMessage(error instanceof Error ? error.message : "Could not make a link."); } }; const remove = async (id: string) => { setMessage(null); try { await removeDevice(id); load(); } catch (error) { setMessage(error instanceof Error ? error.message : "Could not remove that device."); } }; return (

Your devices

These devices sign in with their own fingerprint or face reader.

    {(devices ?? []).map((device) => (
  • {device.name}{here.includes(device.id) ? " (this device)" : ""} Added {when(device.created_at)}{device.last_used ? ` ยท last used ${when(device.last_used)}` : ""}
  • ))}
{link && (

Open this link on the other device within 10 minutes. It works once.

{link}

)} {message &&

{message}

}
); }