UNPKG

payload-auth-plugin

Version:
31 lines (30 loc) 895 B
// src/client/passkey/registration.ts import { startRegistration } from "@simplewebauthn/browser"; var registration = async (email) => { try { const resp = await fetch("/api/admin/passkey/generate-registration-options", { method: "POST", body: JSON.stringify({ data: { email } }) }); const optionsJSON = await resp.json(); const registrationResp = await startRegistration({ optionsJSON: optionsJSON.options }); const response = await fetch("/api/admin/passkey/verify-registration", { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ data: { email, registration: registrationResp } }) }); if (response.redirected) { window.location.href = response.url; } } catch (error) { console.log(error); } }; export { registration };