Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth, iOS): include missing email and credential in account-exists-with-different-credential error #17180

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -602,51 +602,58 @@ static void handleAppleAuthResult(FLTFirebaseAuthPlugin *object, AuthPigeonFireb
return;
}
if (credentials) {
[auth signInWithCredential:credentials
completion:^(FIRAuthDataResult *authResult, NSError *error) {
if (error != nil) {
Comment on lines -605 to -607
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole indentation changed because of this which makes reviewing harder, why formatting changed?

NSDictionary *userInfo = [error userInfo];
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];

NSDictionary *firebaseDictionary =
underlyingError.userInfo[@"FIRAuthErrorUserInfoDes"
@"erializedResponseKey"];

if (firebaseDictionary == nil &&
userInfo[@"FIRAuthErrorUserInfoNameKey"] != nil) {
// Removing since it's not parsed and causing issue when sending back the
// object to Flutter
NSMutableDictionary *mutableUserInfo = [userInfo mutableCopy];
[mutableUserInfo
removeObjectForKey:@"FIRAuthErrorUserInfoUpdatedCredentialKey"];
NSError *modifiedError = [NSError errorWithDomain:error.domain
code:error.code
userInfo:mutableUserInfo];

completion(nil,
[FlutterError errorWithCode:@"sign-in-failed"
message:userInfo[@"NSLocalizedDescription"]
details:modifiedError.userInfo]);

} else if (firebaseDictionary != nil &&
firebaseDictionary[@"message"] != nil) {
// error from firebase-ios-sdk is
// buried in underlying error.
completion(nil,
[FlutterError errorWithCode:@"sign-in-failed"
message:error.localizedDescription
details:firebaseDictionary[@"message"]]);
} else {
completion(nil, [FlutterError errorWithCode:@"sign-in-failed"
message:error.localizedDescription
details:error.userInfo]);
[auth
signInWithCredential:credentials
completion:^(FIRAuthDataResult *authResult, NSError *error) {
if (error != nil) {
NSDictionary *userInfo = [error userInfo];
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];

NSDictionary *firebaseDictionary =
underlyingError.userInfo[@"FIRAuthErrorUserInfoDes"
@"erializedResponseKey"];

NSString *errorCode = userInfo[@"FIRAuthErrorUserInfoNameKey"];

if (firebaseDictionary == nil && errorCode != nil) {
if ([errorCode isEqual:@"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL"]) {
completion(nil, [FLTFirebaseAuthPlugin convertToFlutterError:error]);
return;
}

// Removing since it's not parsed and causing issue when sending back the
// object to Flutter
NSMutableDictionary *mutableUserInfo = [userInfo mutableCopy];
[mutableUserInfo
removeObjectForKey:@"FIRAuthErrorUserInfoUpdatedCredentialKey"];
NSError *modifiedError = [NSError errorWithDomain:error.domain
code:error.code
userInfo:mutableUserInfo];

completion(nil,
[FlutterError errorWithCode:@"sign-in-failed"
message:userInfo[@"NSLocalizedDescription"]
details:modifiedError.userInfo]);

} else if (firebaseDictionary != nil &&
firebaseDictionary[@"message"] != nil) {
// error from firebase-ios-sdk is
// buried in underlying error.
completion(nil,
[FlutterError errorWithCode:@"sign-in-failed"
message:error.localizedDescription
details:firebaseDictionary[@"message"]]);
} else {
completion([PigeonParser getPigeonUserCredentialFromAuthResult:authResult
authorizationCode:nil],
nil);
Comment on lines -645 to -647
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see here that you have changed the order in completion, is this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake it's because the whole indentation changed 😓

completion(nil, [FlutterError errorWithCode:@"sign-in-failed"
message:error.localizedDescription
details:error.userInfo]);
}
}];
} else {
completion([PigeonParser getPigeonUserCredentialFromAuthResult:authResult
authorizationCode:nil],
nil);
}
}];
}
}

Expand Down
Loading