-
Notifications
You must be signed in to change notification settings - Fork 26
Fix iOS error handling for excludeCredentials (issue #45) #54
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughiOS error handling for excludeCredentials is improved by detecting generic iOS error messages and mapping ASAuthorizationError codes to appropriate WebAuthn error names. A test function is added to the example app, and new exception classes are introduced to support descriptive error messages across all failure cases. Changes
Sequence DiagramsequenceDiagram
participant User
participant App as Example App
participant Module as ReactNativePasskeysModule
participant iOS as iOS ASAuthorizationController
participant Exceptions as Exception Classes
User->>App: Tap "Test excludeCredentials"
App->>Module: Call createPasskey with excludeCredentials
Module->>iOS: Request passkey creation
iOS-->>Module: Return ASAuthorizationError (e.g., code 1006)
rect rgb(200, 220, 255)
Note over Module: Error Detection & Mapping
Module->>Module: Call isGenericErrorMessage()
Module->>Module: Map error code to WebAuthn equivalent
Module->>Exceptions: Create mapped exception<br/>(e.g., InvalidStateError)
end
Exceptions-->>Module: Return exception with descriptive message
Module-->>App: Reject with mapped error
App-->>User: Display error (e.g., "credential already exists")
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.changeset/fix-invalid-state-error-45.md(1 hunks)example/src/app/index.tsx(2 hunks)ios/PasskeyExceptions.swift(2 hunks)ios/ReactNativePasskeysModule.swift(1 hunks)
| const json = await passkey.create({ | ||
| ...createOptions, | ||
| excludeCredentials: [{ id: credentialId, type: "public-key" }], | ||
| }); | ||
|
|
||
| console.log("excludeCredentials test result -", json); | ||
| alert("Unexpected Success", "This should have failed with InvalidStateError"); | ||
| setResult(json); | ||
| } catch (e) { |
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.
Fix undefined createOptions reference before shipping.
testExcludeCredentials spreads createOptions, but nothing with that name is defined in this component. Hitting the new button will immediately throw a ReferenceError instead of reproducing the iOS error flow, so the demo can’t validate the fix. Bring the full creation payload inline (or share it from createPasskey) before calling passkey.create.
- const json = await passkey.create({
- ...createOptions,
- excludeCredentials: [{ id: credentialId, type: "public-key" }],
- });
+ const json = await passkey.create({
+ challenge,
+ pubKeyCredParams: [{ alg: -7, type: "public-key" }],
+ rp,
+ user,
+ authenticatorSelection,
+ extensions: {
+ ...(Platform.OS !== "android" && { largeBlob: { support: "required" } }),
+ prf: {},
+ },
+ excludeCredentials: [{ id: credentialId, type: "public-key" }],
+ });Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In example/src/app/index.tsx around lines 227 to 235, the function
testExcludeCredentials references createOptions which is undefined causing a
ReferenceError; replace the spread with the actual creation payload (either
inline the full create options object used elsewhere or import/share the
createPasskey payload) so passkey.create receives a complete, defined options
object including challenge, rp, user, pubKeyCredParams, timeout, and any other
required fields; ensure excludeCredentials is merged into that defined object
before calling passkey.create.
Summary
Fixes #45 - excludeCredentials does not return expected InvalidStateError message when credential already exists
This PR enhances iOS error handling to provide clear, descriptive error messages instead of generic "(null)" or "The operation couldn't be completed" messages.
Changes
Files Changed
ios/PasskeyExceptions.swift: Added new exception classes for different error typesios/ReactNativePasskeysModule.swift: EnhancedhandleASAuthorizationErrorfunction with generic error detection and proper error mappingexample/src/app/index.tsx: Added test button to demonstrate excludeCredentials error handlingTesting
Run the example app and use the new "Test excludeCredentials" button to verify that attempting to create a credential that's already registered returns a proper InvalidStateError with a descriptive message.
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes