-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Show separate error message when adding a Passkey twice #2756
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,9 +77,9 @@ class PasskeyButton extends HTMLElement { | |
|
|
||
| #handleError(error) { | ||
| console.error("Passkey ceremony failed", error) | ||
| const cancelled = error.name === "AbortError" || error.name === "NotAllowedError" | ||
| this.#showError(cancelled ? "cancelled" : "error") | ||
| this.button.dispatchEvent(new CustomEvent("passkey:error", { bubbles: true, detail: { error, cancelled } })) | ||
| const type = errorType(error) | ||
| this.#showError(type) | ||
| this.button.dispatchEvent(new CustomEvent("passkey:error", { bubbles: true, detail: { error, type } })) | ||
| } | ||
|
Comment on lines
+82
to
+83
|
||
|
|
||
| #showError(type) { | ||
|
|
@@ -139,8 +139,8 @@ class PasskeySignInButton extends PasskeyButton { | |
| this.form.submit() | ||
| } catch (error) { | ||
| console.error("Passkey conditional mediation failed", error) | ||
| const cancelled = error.name === "AbortError" || error.name === "NotAllowedError" | ||
| this.button.dispatchEvent(new CustomEvent("passkey:error", { bubbles: true, detail: { error, cancelled } })) | ||
| const type = errorType(error) | ||
| this.button.dispatchEvent(new CustomEvent("passkey:error", { bubbles: true, detail: { error, type } })) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -157,6 +157,15 @@ customElements.define("rails-passkey-sign-in-button", PasskeySignInButton) | |
|
|
||
| // -- Shared helpers ---------------------------------------------------------- | ||
|
|
||
| function errorType(error) { | ||
| switch (error.name) { | ||
| case "AbortError": | ||
| case "NotAllowedError": return "cancelled" | ||
| case "InvalidStateError": return "duplicate" | ||
| default: return "error" | ||
| } | ||
| } | ||
|
|
||
| function passkeysAvailable() { | ||
| return !!window.PublicKeyCredential | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InvalidStateErroris mapped to the new "duplicate" error type for all passkey ceremonies, but only the registration helper sets a default duplicate message. Combined with the always-rendered (but potentially empty) duplicate div, this can lead to a blank error display. Consider scoping the "duplicate" handling to registration (this.purpose === "registration"), or making#showErrorfall back to the generic "error" message when the requested error element is missing/empty.