passkey existing
This commit is contained in:
@@ -251,6 +251,26 @@
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector("[data-passkey-add]")?.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const support = await checkPasskeySupport();
|
||||
if (!support.supported) {
|
||||
setStatus("[data-passkey-add-status]", support.reason, true);
|
||||
return;
|
||||
}
|
||||
if (support.reason) {
|
||||
console.warn("Passkey support:", support.reason);
|
||||
}
|
||||
try {
|
||||
const begin = await postJSON("/api/auth/passkeys/me/register/begin", {});
|
||||
const credential = await navigator.credentials.create(normalizeCreateOptions(begin.options));
|
||||
await postJSON(`/api/auth/passkeys/me/register/finish?challengeId=${encodeURIComponent(begin.challengeId)}`, credentialToJSON(credential));
|
||||
setStatus("[data-passkey-add-status]", "Passkey added. You can use it the next time you sign in.");
|
||||
} catch (error) {
|
||||
setStatus("[data-passkey-add-status]", webAuthnErrorMessage(error), true);
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector("[data-auth-logout]")?.addEventListener("click", async () => {
|
||||
try {
|
||||
await postJSON("/api/auth/logout", {});
|
||||
|
||||
Reference in New Issue
Block a user