@@ -130,7 +130,20 @@ public final class AuthService {
130130 public var currentUser : User ?
131131 public var authenticationState : AuthenticationState = . unauthenticated
132132 public var authenticationFlow : AuthenticationFlow = . signIn
133- public private( set) var currentError : AlertError ?
133+ private var _currentError : AlertError ?
134+
135+ /// A binding that allows SwiftUI views to observe and clear errors
136+ public var currentError : Binding < AlertError ? > {
137+ Binding (
138+ get: { self . _currentError } ,
139+ set: { newValue in
140+ if newValue == nil {
141+ self . _currentError = nil
142+ }
143+ }
144+ )
145+ }
146+
134147 public let passwordPrompt : PasswordPromptCoordinator = . init( )
135148 public var currentMFARequired : MFARequired ?
136149 private var currentMFAResolver : MultiFactorResolver ?
@@ -207,12 +220,12 @@ public final class AuthService {
207220 }
208221
209222 func reset( ) {
210- currentError = nil
223+ _currentError = nil
211224 currentAccountConflict = nil
212225 }
213226
214227 func updateError( title: String = " Error " , message: String , underlyingError: Error ? = nil ) {
215- currentError = AlertError ( title: title, message: message, underlyingError: underlyingError)
228+ _currentError = AlertError ( title: title, message: message, underlyingError: underlyingError)
216229 }
217230
218231 public var shouldHandleAnonymousUpgrade : Bool {
@@ -286,7 +299,7 @@ public final class AuthService {
286299 return handleMFARequiredError ( resolver: resolver)
287300 }
288301 }
289-
302+
290303 // Possible conflicts from auth.signIn(with:):
291304 // - accountExistsWithDifferentCredential: account exists with different provider
292305 // - credentialAlreadyInUse: credential is already linked to another account
@@ -443,7 +456,7 @@ public extension AuthService {
443456 . invalidEmailLink ( " email address is missing from app storage. Is this the same device? " )
444457 }
445458 let credential = EmailAuthProvider . credential ( withEmail: email, link: link)
446-
459+
447460 // Possible conflicts from auth.signIn(withEmail:link:):
448461 // - accountExistsWithDifferentCredential: account exists with different provider
449462 // - credentialAlreadyInUse: credential is already linked to another account
@@ -883,8 +896,10 @@ public extension AuthService {
883896 /// - Parameters:
884897 /// - error: The error to check and handle
885898 /// - credential: The credential that caused the conflict
886- /// - Throws: AuthServiceError.accountConflict if it's a conflict error, otherwise rethrows the original error
887- private func handleErrorWithConflictCheck( error: Error , credential: AuthCredential ) throws -> Never {
899+ /// - Throws: AuthServiceError.accountConflict if it's a conflict error, otherwise rethrows the
900+ /// original error
901+ private func handleErrorWithConflictCheck( error: Error ,
902+ credential: AuthCredential ) throws -> Never {
888903 // Check for account conflict errors
889904 if let error = error as NSError ? ,
890905 let conflictType = determineConflictType ( from: error) {
@@ -893,15 +908,15 @@ public extension AuthService {
893908 conflictType: conflictType,
894909 credential: credential
895910 )
896-
911+
897912 // Store it for consumers to observe
898913 currentAccountConflict = context
899-
914+
900915 // Only set error alert if we're NOT auto-handling it
901916 if conflictType != . anonymousUpgradeConflict {
902917 updateError ( message: context. message, underlyingError: error)
903918 }
904-
919+
905920 // Throw the specific error with context
906921 throw AuthServiceError . accountConflict ( context)
907922 } else {
0 commit comments