refactor: error handling, merge conflicts and auto anonymous upgrade #1292
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.
Account Conflict Handling: Typed Errors & Auto-Recovery for Anonymous Users
Summary
This PR introduces a comprehensive, type-safe system for handling account credential conflicts during sign-in, with special support for automatic anonymous user upgrade recovery. The implementation separates concerns between the service layer (AuthService) and view layer (AuthPickerView), allowing both opinionated default behaviour and flexible custom implementations if the consumer decides to implement their own custom Views.
What Changed
1. Typed Account Conflict System (
AuthServiceError.swift)Added structured conflict types to replace generic error handling:
Renamed:
AuthServiceError.accountMergeConflict→AuthServiceError.accountConflict2. Dual-Purpose Error Properties (
AuthService.swift)Added observable property for programmatic conflict handling while maintaining existing error alert system:
AuthServicedetects the error typecurrentAccountConflictwith full context (always)currentErrorfor user-facing alerts (except for auto-handled conflicts)AuthServiceError.accountConflictfor immediate error handling3. Opinionated View Layer: Auto-Recovery (
AuthPickerView.swift)AuthPickerView now automatically handles anonymous user upgrade conflicts:
Behavior:
4. Smart Alert Filtering (
ErrorAlertView.swift)Updated
ErrorAlertModifierto prevent showing alerts for auto-handled conflicts:Using the API in Custom Views
Consumers can observe
currentAccountConflictto implement custom behaviour or update their backend:Or catch the error directly: