@@ -602,51 +602,71 @@ static void handleAppleAuthResult(FLTFirebaseAuthPlugin *object, AuthPigeonFireb
602602 return ;
603603 }
604604 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];
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 ];
625611
626- completion (nil ,
627- [FlutterError errorWithCode: @" sign-in-failed"
628- message: userInfo[@" NSLocalizedDescription" ]
629- details: modifiedError.userInfo]);
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+ FIRAuthCredential *authCredential =
621+ userInfo[@" FIRAuthErrorUserInfoUpdatedCredentialKey" ];
622+
623+ PigeonAuthCredential *pigeonAuthCredential =
624+ [PigeonParser getPigeonAuthCredential: authCredential token: nil ];
630625
631- } else if (firebaseDictionary != nil &&
632- firebaseDictionary [@" message " ] != nil ) {
633- // error from firebase-ios-sdk is
634- // buried in underlying error.
626+ NSDictionary *errorDetails = @{
627+ @" email " : error. userInfo [@" FIRAuthErrorUserInfoEmailKey " ],
628+ @" authCredential " : pigeonAuthCredential
629+ };
635630 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]);
631+ [FlutterError errorWithCode: errorCode
632+ message: userInfo[@" NSLocalizedDescription" ]
633+ details: errorDetails]);
634+ return ;
643635 }
636+
637+ // Removing since it's not parsed and causing issue when sending back the
638+ // object to Flutter
639+ NSMutableDictionary *mutableUserInfo = [userInfo mutableCopy ];
640+ [mutableUserInfo
641+ removeObjectForKey: @" FIRAuthErrorUserInfoUpdatedCredentialKey" ];
642+ NSError *modifiedError = [NSError errorWithDomain: error.domain
643+ code: error.code
644+ userInfo: mutableUserInfo];
645+
646+ completion (nil ,
647+ [FlutterError errorWithCode: @" sign-in-failed"
648+ message: userInfo[@" NSLocalizedDescription" ]
649+ details: modifiedError.userInfo]);
650+
651+ } else if (firebaseDictionary != nil &&
652+ firebaseDictionary[@" message" ] != nil ) {
653+ // error from firebase-ios-sdk is
654+ // buried in underlying error.
655+ completion (nil ,
656+ [FlutterError errorWithCode: @" sign-in-failed"
657+ message: error.localizedDescription
658+ details: firebaseDictionary[@" message" ]]);
644659 } else {
645- completion ([PigeonParser getPigeonUserCredentialFromAuthResult: authResult
646- authorizationCode: nil ],
647- nil );
660+ completion (nil , [FlutterError errorWithCode: @" sign-in-failed "
661+ message: error.localizedDescription
662+ details: error.userInfo] );
648663 }
649- }];
664+ } else {
665+ completion ([PigeonParser getPigeonUserCredentialFromAuthResult: authResult
666+ authorizationCode: nil ],
667+ nil );
668+ }
669+ }];
650670 }
651671}
652672
0 commit comments