@@ -602,51 +602,58 @@ static void handleAppleAuthResult(FLTFirebaseAuthPlugin *object, AuthPigeonFireb
602
602
return ;
603
603
}
604
604
if (credentials) {
605
- [auth signInWithCredential: credentials
606
- completion: ^(FIRAuthDataResult *authResult, NSError *error) {
607
- if (error != nil ) {
608
- NSDictionary *userInfo = [error userInfo ];
609
- NSError *underlyingError = [userInfo objectForKey: NSUnderlyingErrorKey ];
610
-
611
- NSDictionary *firebaseDictionary =
612
- underlyingError.userInfo [@" FIRAuthErrorUserInfoDes"
613
- @" erializedResponseKey" ];
614
-
615
- if (firebaseDictionary == nil &&
616
- userInfo[@" FIRAuthErrorUserInfoNameKey" ] != nil ) {
617
- // Removing since it's not parsed and causing issue when sending back the
618
- // object to Flutter
619
- NSMutableDictionary *mutableUserInfo = [userInfo mutableCopy ];
620
- [mutableUserInfo
621
- removeObjectForKey: @" FIRAuthErrorUserInfoUpdatedCredentialKey" ];
622
- NSError *modifiedError = [NSError errorWithDomain: error.domain
623
- code: error.code
624
- userInfo: mutableUserInfo];
625
-
626
- completion (nil ,
627
- [FlutterError errorWithCode: @" sign-in-failed"
628
- message: userInfo[@" NSLocalizedDescription" ]
629
- details: modifiedError.userInfo]);
630
-
631
- } else if (firebaseDictionary != nil &&
632
- firebaseDictionary[@" message" ] != nil ) {
633
- // error from firebase-ios-sdk is
634
- // buried in underlying error.
635
- completion (nil ,
636
- [FlutterError errorWithCode: @" sign-in-failed"
637
- message: error.localizedDescription
638
- details: firebaseDictionary[@" message" ]]);
639
- } else {
640
- completion (nil , [FlutterError errorWithCode: @" sign-in-failed"
641
- message: error.localizedDescription
642
- details: error.userInfo]);
605
+ [auth
606
+ signInWithCredential: credentials
607
+ completion: ^(FIRAuthDataResult *authResult, NSError *error) {
608
+ if (error != nil ) {
609
+ NSDictionary *userInfo = [error userInfo ];
610
+ NSError *underlyingError = [userInfo objectForKey: NSUnderlyingErrorKey ];
611
+
612
+ NSDictionary *firebaseDictionary =
613
+ underlyingError.userInfo [@" FIRAuthErrorUserInfoDes"
614
+ @" erializedResponseKey" ];
615
+
616
+ NSString *errorCode = userInfo[@" FIRAuthErrorUserInfoNameKey" ];
617
+
618
+ if (firebaseDictionary == nil && errorCode != nil ) {
619
+ if ([errorCode isEqual: @" ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL" ]) {
620
+ completion (nil , [FLTFirebaseAuthPlugin convertToFlutterError: error]);
621
+ return ;
643
622
}
623
+
624
+ // Removing since it's not parsed and causing issue when sending back the
625
+ // object to Flutter
626
+ NSMutableDictionary *mutableUserInfo = [userInfo mutableCopy ];
627
+ [mutableUserInfo
628
+ removeObjectForKey: @" FIRAuthErrorUserInfoUpdatedCredentialKey" ];
629
+ NSError *modifiedError = [NSError errorWithDomain: error.domain
630
+ code: error.code
631
+ userInfo: mutableUserInfo];
632
+
633
+ completion (nil ,
634
+ [FlutterError errorWithCode: @" sign-in-failed"
635
+ message: userInfo[@" NSLocalizedDescription" ]
636
+ details: modifiedError.userInfo]);
637
+
638
+ } else if (firebaseDictionary != nil &&
639
+ firebaseDictionary[@" message" ] != nil ) {
640
+ // error from firebase-ios-sdk is
641
+ // buried in underlying error.
642
+ completion (nil ,
643
+ [FlutterError errorWithCode: @" sign-in-failed"
644
+ message: error.localizedDescription
645
+ details: firebaseDictionary[@" message" ]]);
644
646
} else {
645
- completion ([PigeonParser getPigeonUserCredentialFromAuthResult: authResult
646
- authorizationCode: nil ],
647
- nil );
647
+ completion (nil , [FlutterError errorWithCode: @" sign-in-failed "
648
+ message: error.localizedDescription
649
+ details: error.userInfo] );
648
650
}
649
- }];
651
+ } else {
652
+ completion ([PigeonParser getPigeonUserCredentialFromAuthResult: authResult
653
+ authorizationCode: nil ],
654
+ nil );
655
+ }
656
+ }];
650
657
}
651
658
}
652
659
0 commit comments