diff options
author | Matthew Miller <matthew@millerti.me> | 2022-07-04 08:04:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-04 08:04:44 -0700 |
commit | 184cbb4457285817db4ded722d7b54528988e2e0 (patch) | |
tree | 3b895f8c273e924dd6fdd52c50fd2528575dc41d /packages/browser/src/helpers/webAuthnAbortService.ts | |
parent | 524e7f881624f36aa17f406bb25fa23d02449652 (diff) | |
parent | 5a5b5a3bdf7c709493fc9e63f0f02eed99f25baf (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.ts | 27 |
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(); |