MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.62k stars 137 forks source link

Export WebAuthnError #505

Closed zoontek closed 10 months ago

zoontek commented 10 months ago

Hi πŸ‘‹

First, thanks a lot for this library, it's a life-saviour when using WebAuthn. I have a small question, are you against exporting WebAuthnError? This way, we could be able to perform instanceof checks instead of duck typing:

// usage example with ts-pattern:
startAuthentication({ … }).catch(error => {
  if (error instanceof WebAuthnError) {
    match(error.code) // typesafe here
      .with("ERROR_AUTHENTICATOR_GENERAL_ERROR", () => { … })
      .with("ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT", () => { … })
      .with("ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT", () => { … })
      .with("ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG", () => { … })
      .with("ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED", () => { … })
      .with("ERROR_CEREMONY_ABORTED", () => { … })
      .with("ERROR_INVALID_DOMAIN", () => { … })
      .with("ERROR_INVALID_RP_ID", () => { … })
      .with("ERROR_INVALID_USER_ID_LENGTH", () => { … })
      .with("ERROR_MALFORMED_PUBKEYCREDPARAMS", () => { … })
      .with("ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", () => { … })
      .exhaustive();
  }
});

If you are against it, feel free to close this PR.

MasterKale commented 10 months ago

I have no issue with this at all, thanks for the contribution @zoontek! I'll get this merged and published Soonβ„’ ✌️

MasterKale commented 10 months ago

Hello @zoontek, thanks for your patience. You should now be able to import WebAuthnError from @simplewebauthn/browser@8.3.7! πŸš€