Bridge FirebaseAuthException to an iOS-shaped NSError - #99
Merged
Conversation
Android auth failures reached Swift as a bare `ErrorException`. Its
`localizedDescription` is the generic bridge text ("The operation could not
be completed. (SwiftJNI.ThrowableError error 1.)"), so a caller could not
tell "wrong password" from "email already in use" — and any message it
derived from the error was wrong. On iOS the same failures carry
`FIRAuthErrorDomain` plus a `FIRAuthErrorCode`, which is what cross-platform
callers key off.
`mapAuthNSError` now resolves `FirebaseAuthException.getErrorCode()` to the
matching `FIRAuthErrorCode` raw value and keeps the Android message in
`NSLocalizedDescriptionKey`, with a fallback on the exception class for
unknown codes. `FirebaseNetworkException` (not a FirebaseAuthException, no
error code) maps to `.networkError`. `AuthErrorCode` grows from one case to
the resolvable set.
The mapping was previously only applied on the completion-handler paths; the
`async throws` ones threw straight through. signIn(withEmail:),
createUser(withEmail:), sendPasswordReset(withEmail:),
User.sendEmailVerification(), User.reauthenticate(with:) and User.delete()
now go through it too.
Mirrors `asNSError(functionsException:)` in SkipFirebaseFunctions (skiptools#95) and
`asNSError(firestoreException:)` in SkipFirebaseFirestore.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MxxbQFDQyDkNvFMZaV5Aij
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Android auth failures currently reach Swift as a bare
ErrorException. ItslocalizedDescriptionis the generic bridge text (The operation could not be completed. (SwiftJNI.ThrowableError error 1.)), so a caller cannot tell "wrong password" from "email already in use" — and any message it derives from the error is wrong. On iOS the same failures carryFIRAuthErrorDomainplus aFIRAuthErrorCode, which is what cross-platform callers key off.mapAuthNSErrorresolvesFirebaseAuthException.getErrorCode()to the matchingFIRAuthErrorCoderaw value and keeps the Android message inNSLocalizedDescriptionKey, falling back to the exception class for unknown codes.FirebaseNetworkException(not aFirebaseAuthException, no error code) maps to.networkError.AuthErrorCodegrows from one case to the resolvable set.async throwsones threw straight through.signIn(withEmail:),createUser(withEmail:),sendPasswordReset(withEmail:),User.sendEmailVerification(),User.reauthenticate(with:)andUser.delete()now go through it too.Mirrors
asNSError(functionsException:)in SkipFirebaseFunctions (#95) andasNSError(firestoreException:)in SkipFirebaseFirestore.Verified on an Android 16 emulator against a real Firebase project: sign-in with a wrong password, registration with an address already in use, and re-authentication with a wrong password each now arrive as
FIRAuthErrorDomainwith the code iOS reports for the same case. Nothing in the iOS path changes (the file is#elseif SKIP).