Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export WebAuthnError #505

Merged
merged 1 commit into from
Jan 20, 2024
Merged

Conversation

zoontek
Copy link
Contributor

@zoontek zoontek commented Jan 18, 2024

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
Copy link
Owner

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

@MasterKale MasterKale added the package:browser @simplewebauthn/browser label Jan 20, 2024
@MasterKale MasterKale added this to the v8.3.7 milestone Jan 20, 2024
@MasterKale MasterKale merged commit 2f4d01b into MasterKale:master Jan 20, 2024
2 checks passed
@MasterKale
Copy link
Owner

Hello @zoontek, thanks for your patience. You should now be able to import WebAuthnError from @simplewebauthn/[email protected]! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:browser @simplewebauthn/browser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants