window.addEventListener("DOMContentLoaded", function() { const registerBtn = document.querySelector("#register"); registerBtn?.addEventListener("click", async function() { await fetch("/users/register/setup", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ username: "arthur" }) }) .then((data) => { return data.json(); }) .then((data) => { console.log("we received:", data); return SimpleWebAuthnBrowser.startRegistration({ optionsJSON: data }); }) .then((attResp) => { return fetch("/users/register/verify", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ registration: attResp, username: 'arthur' }) }); }) .then((response) => { return response.json(); }) .then((data) => { console.log("Le finish"); console.log(data); }) .catch((err) => { console.error("Something went wrong"); console.error(err); }); }); });