summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/webAuthnAbortService.ts
blob: 35e2f290734ada0860d8d0ebadcf6a80c11ec203 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
 * 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.get()
    if (this.controller) {
      this.controller.abort();
    }

    this.controller = new AbortController();
    return this.controller.signal;
  }
}

export const webauthnAbortService = new WebAuthnAbortService();