summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/webAuthnAbortService.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-07-04 08:04:44 -0700
committerGitHub <noreply@github.com>2022-07-04 08:04:44 -0700
commit184cbb4457285817db4ded722d7b54528988e2e0 (patch)
tree3b895f8c273e924dd6fdd52c50fd2528575dc41d /packages/browser/src/helpers/webAuthnAbortService.ts
parent524e7f881624f36aa17f406bb25fa23d02449652 (diff)
parent5a5b5a3bdf7c709493fc9e63f0f02eed99f25baf (diff)
Merge pull request #214 from MasterKale/feat/conditional-ui
feat/conditional-ui
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();