Skip to content

Commit e955895

Browse files
authored
Merge pull request #966 from numerique-gouv/catch-more-webauthn-errors
fix: catch fetch error during webauthn authentication
2 parents b68f8b0 + 99bc601 commit e955895

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

assets/js/webauthn-authentication.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ document.addEventListener(
3333
errorElement.innerText = "";
3434
beginElement.disabled = true;
3535

36-
// GET registration options from the endpoint that calls
37-
// @simplewebauthn/server -> generateRegistrationOptions()
38-
const authOptions = await fetch(authOptionsUrl);
39-
4036
let asseResp;
37+
4138
try {
39+
// GET registration options from the endpoint that calls
40+
// @simplewebauthn/server -> generateRegistrationOptions()
41+
const authOptions = await fetch(authOptionsUrl);
42+
4243
// Pass the options to the authenticator and wait for a response
4344
asseResp = await startAuthentication(await authOptions.json());
4445
} catch (error) {
@@ -66,8 +67,9 @@ document.addEventListener(
6667
const hasNotification = urlParams.get("notification") !== null;
6768

6869
if (!hasNotification) {
69-
const authOptions = await fetch(authOptionsUrl);
7070
try {
71+
const authOptions = await fetch(authOptionsUrl);
72+
7173
let asseResp = await startAuthentication(
7274
await authOptions.json(),
7375
true,
@@ -78,6 +80,7 @@ document.addEventListener(
7880
authenticationResponseForm.requestSubmit();
7981
} catch (e) {
8082
// fail silently
83+
console.error(e);
8184
}
8285
}
8386
};

assets/js/webauthn-registration.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ document.addEventListener(
3232
clearDisplay();
3333
beginElement.disabled = true;
3434

35-
// GET registration options from the endpoint that calls
36-
// @simplewebauthn/server -> generateRegistrationOptions()
37-
const resp = await fetch("/api/webauthn/generate-registration-options");
38-
3935
let attResp;
36+
4037
try {
38+
// GET registration options from the endpoint that calls
39+
// @simplewebauthn/server -> generateRegistrationOptions()
40+
const resp = await fetch("/api/webauthn/generate-registration-options");
41+
4142
// Pass the options to the authenticator and wait for a response
4243
attResp = await startRegistration(await resp.json());
4344
} catch (error) {

0 commit comments

Comments
 (0)