@@ -245,24 +245,6 @@ public final class AuthService {
245245 }
246246 }
247247
248- // Real account? → Requires proof of ownership → requiresManualLinking = true
249- private func handleAccountExistsError( _ error: NSError , with credentials: AuthCredential ) throws {
250- let email = error. userInfo [ " FIRAuthErrorUserInfoEmailKey " ] as? String
251- let updatedCredential = error. userInfo [ " FIRAuthUpdatedCredentialKey " ] as? AuthCredential
252- ?? credentials
253-
254- let context = AccountMergeConflictContext (
255- credential: updatedCredential,
256- underlyingError: error,
257- message: " An account already exists with \( email ?? " this email " ) . Please sign in with your existing method to link accounts. " ,
258- uid: nil ,
259- email: email,
260- requiresManualLinking: true
261- )
262-
263- throw AuthServiceError . accountMergeConflict ( context: context)
264- }
265-
266248 private func handleAutoUpgradeAnonymousUser( credentials: AuthCredential ) async throws
267249 -> SignInOutcome {
268250 if currentUser == nil {
@@ -272,42 +254,8 @@ public final class AuthService {
272254 let result = try await currentUser? . link ( with: credentials)
273255 updateAuthenticationState ( )
274256 return . signedIn( result)
275- } catch let error as NSError {
276- // Handle accountExistsWithDifferentCredential error
277- if error. code == AuthErrorCode . accountExistsWithDifferentCredential. rawValue {
278- try handleAccountExistsError ( error, with: credentials)
279- }
280-
281- // Handle credentialAlreadyInUse error
282- if error. code == AuthErrorCode . credentialAlreadyInUse. rawValue {
283- // Extract the updated credential from the error
284- let updatedCredential = error. userInfo [ " FIRAuthUpdatedCredentialKey " ] as? AuthCredential
285- ?? credentials
286- let context = AccountMergeConflictContext (
287- credential: updatedCredential,
288- underlyingError: error,
289- message: " Unable to merge accounts. The credential is already associated with a different account. " ,
290- uid: currentUser? . uid,
291- email: nil ,
292- // Anonymous account? → Safe to discard → requiresManualLinking = false
293- requiresManualLinking: false
294- )
295- throw AuthServiceError . accountMergeConflict ( context: context)
296- }
297-
298- // Handle emailAlreadyInUse error
299- if error. code == AuthErrorCode . emailAlreadyInUse. rawValue {
300- let context = AccountMergeConflictContext (
301- credential: credentials,
302- underlyingError: error,
303- message: " Unable to merge accounts. This email is already associated with a different account. " ,
304- uid: currentUser? . uid,
305- email: nil ,
306- // Anonymous account? → Safe to discard → requiresManualLinking = false
307- requiresManualLinking: false
308- )
309- throw AuthServiceError . accountMergeConflict ( context: context)
310- }
257+ } catch {
258+ // Always throw errors - let view layer decide what to do
311259 throw error
312260 }
313261 }
@@ -325,11 +273,6 @@ public final class AuthService {
325273 } catch let error as NSError {
326274 authenticationState = . unauthenticated
327275
328- // Handle account exists with different credential
329- if error. code == AuthErrorCode . accountExistsWithDifferentCredential. rawValue {
330- try handleAccountExistsError ( error, with: credentials)
331- }
332-
333276 // Check if this is an MFA required error
334277 if error. code == AuthErrorCode . secondFactorRequired. rawValue {
335278 if let resolver = error
@@ -427,7 +370,9 @@ public extension AuthService {
427370 }
428371 } catch {
429372 authenticationState = . unauthenticated
373+ // ALWAYS store error - let view layer decide what to do
430374 updateError ( message: string. localizedErrorMessage ( for: error) , underlyingError: error)
375+ // ALWAYS throw - let view layer decide how to handle
431376 throw error
432377 }
433378 }
0 commit comments