2020-01-15 05:27:12 -05:00
|
|
|
import { getWebauthnCredential } from "discourse/lib/webauthn";
|
|
|
|
|
2020-03-11 09:43:55 -04:00
|
|
|
const security = document.getElementById("submit-security-key");
|
|
|
|
if (security) {
|
|
|
|
security.onclick = function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
getWebauthnCredential(
|
|
|
|
document.getElementById("security-key-challenge").value,
|
|
|
|
document
|
|
|
|
.getElementById("security-key-allowed-credential-ids")
|
|
|
|
.value.split(","),
|
|
|
|
(credentialData) => {
|
2022-07-06 04:37:54 -04:00
|
|
|
document.getElementById("security-key-credential").value =
|
|
|
|
JSON.stringify(credentialData);
|
2020-01-15 05:27:12 -05:00
|
|
|
|
2023-04-25 08:40:18 -04:00
|
|
|
e.target.closest("form").submit();
|
2020-03-11 09:43:55 -04:00
|
|
|
},
|
|
|
|
(errorMessage) => {
|
2023-04-25 08:40:18 -04:00
|
|
|
document.getElementById(
|
|
|
|
"security-key-error"
|
|
|
|
).innerHTML = `<div class="alert alert-error"></div>`;
|
|
|
|
document.querySelector("#security-key-error .alert").innerText =
|
|
|
|
errorMessage;
|
2020-03-11 09:43:55 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|