summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/webAuthnAbortService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src/helpers/webAuthnAbortService.ts')
-rw-r--r--packages/browser/src/helpers/webAuthnAbortService.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/webAuthnAbortService.ts b/packages/browser/src/helpers/webAuthnAbortService.ts
new file mode 100644
index 0000000..c60e6df
--- /dev/null
+++ b/packages/browser/src/helpers/webAuthnAbortService.ts
@@ -0,0 +1,27 @@
+/**
+ * A way to cancel an existing WebAuthn request, for example to cancel a
+ * WebAuthn autofill authentication request for a manual authentication attempt.
+ */
+class WebAuthnAbortService {
+ private controller: AbortController | undefined;
+
+ /**
+ * Prepare an abort signal that will help support multiple auth attempts without needing to
+ * reload the page
+ */
+ createNewAbortSignal() {
+ // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get()
+ if (this.controller) {
+ this.controller.abort();
+ }
+
+ this.controller = new AbortController();
+ return this.controller.signal;
+ }
+
+ reset() {
+ this.controller = undefined;
+ }
+}
+
+export const webauthnAbortService = new WebAuthnAbortService();