From 986ff6a58959bdfa967f9d36034c0b85937c7d10 Mon Sep 17 00:00:00 2001
From: Florent Morselli <florent.morselli@spomky-labs.com>
Date: Sat, 18 Jan 2025 16:31:19 +0100
Subject: [PATCH] Event dispatch payloads for WebAuthn failure cases

Update failure event payloads to include additional context, such as `assertionResponse` or `optionsResponse`, improving error handling consistency. This ensures downstream handlers have access to more detailed information during WebAuthn failures.
---
 src/stimulus/assets/dist/controller.js | 6 +++---
 src/stimulus/assets/src/controller.ts  | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/stimulus/assets/dist/controller.js b/src/stimulus/assets/dist/controller.js
index 920f6e6e..aa8c80f5 100644
--- a/src/stimulus/assets/dist/controller.js
+++ b/src/stimulus/assets/dist/controller.js
@@ -47,7 +47,7 @@ class default_1 extends Controller {
             }
         }
         catch (e) {
-            this._dispatchEvent('webauthn:assertion:failure', {exception: e});
+            this._dispatchEvent('webauthn:assertion:failure', { exception: e, assertionResponse: null });
             return;
         }
     }
@@ -70,7 +70,7 @@ class default_1 extends Controller {
             }
         }
         catch (e) {
-            this._dispatchEvent('webauthn:attestation:failure', {exception: e});
+            this._dispatchEvent('webauthn:attestation:failure', { exception: e, assertionResponse: null });
             return;
         }
     }
@@ -120,7 +120,7 @@ class default_1 extends Controller {
             body: JSON.stringify(data)
         });
         if (!optionsResponse.ok) {
-            this._dispatchEvent('webauthn:options:failure', {});
+            this._dispatchEvent('webauthn:options:failure', { exception: null, optionsResponse });
             return false;
         }
         const options = await optionsResponse.json();
diff --git a/src/stimulus/assets/src/controller.ts b/src/stimulus/assets/src/controller.ts
index 7d94d562..a6c6fca7 100644
--- a/src/stimulus/assets/src/controller.ts
+++ b/src/stimulus/assets/src/controller.ts
@@ -91,7 +91,7 @@ export default class extends Controller {
                 window.location.replace(this.requestSuccessRedirectUriValue);
             }
         } catch (e) {
-            this._dispatchEvent('webauthn:assertion:failure', {exception: e});
+            this._dispatchEvent('webauthn:assertion:failure', {exception: e, assertionResponse: null});
             return;
         }
     }
@@ -117,7 +117,7 @@ export default class extends Controller {
                 window.location.replace(this.creationSuccessRedirectUriValue);
             }
         } catch (e) {
-            this._dispatchEvent('webauthn:attestation:failure', {exception: e});
+            this._dispatchEvent('webauthn:attestation:failure', {exception: e, assertionResponse: null});
             return;
         }
     }
@@ -178,7 +178,7 @@ export default class extends Controller {
             body: JSON.stringify(data)
         });
         if (!optionsResponse.ok) {
-            this._dispatchEvent('webauthn:options:failure', {});
+            this._dispatchEvent('webauthn:options:failure', {exception: null, optionsResponse});
             return false;
         }