diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index 03df63e1796e..ba9eb98dde2d 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.14.0+5 + +* On iOS, `fetchSignInMethodsForEmail` now returns an empty list when the email + cannot be found, matching the Android behavior. + ## 0.14.0+4 * Fixed "Register a user" example code snippet in README.md. diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index ab969daaf2e4..52545e1e72b7 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -83,6 +83,10 @@ void main() { password: testPassword, ); expect(result.user.uid, equals(user.uid)); + final List methods = + await auth.fetchSignInMethodsForEmail(email: testEmail); + expect(methods.length, 1); + expect(methods[0], 'password'); await user.delete(); }); @@ -97,5 +101,13 @@ void main() { expect(await auth.isSignInWithEmailLink(emailLink2), false); expect(await auth.isSignInWithEmailLink(emailLink3), false); }); + + test('fetchSignInMethodsForEmail nonexistent user', () async { + final String testEmail = 'testuser${Uuid().v4()}@example.com'; + final List methods = + await auth.fetchSignInMethodsForEmail(email: testEmail); + expect(methods, isNotNull); + expect(methods.length, 0); + }); }); } diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index 61b2498e6560..0700f7489d5f 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -131,7 +131,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [[self getAuth:call.arguments] fetchProvidersForEmail:email completion:^(NSArray *providers, NSError *error) { - [self sendResult:result forObject:providers error:error]; + // For unrecognized emails, the Auth iOS SDK should return an + // empty `NSArray` here, but instead returns `nil`, so we coalesce + // with an empty `NSArray`. + // https://github.com/firebase/firebase-ios-sdk/issues/3655 + [self sendResult:result forObject:providers ?: @[] error:error]; }]; } else if ([@"sendEmailVerification" isEqualToString:call.method]) { [[self getAuth:call.arguments].currentUser diff --git a/packages/firebase_auth/lib/src/firebase_auth.dart b/packages/firebase_auth/lib/src/firebase_auth.dart index 8f0c30a13544..567664be268a 100644 --- a/packages/firebase_auth/lib/src/firebase_auth.dart +++ b/packages/firebase_auth/lib/src/firebase_auth.dart @@ -109,9 +109,10 @@ class FirebaseAuth { /// This method is useful when you support multiple authentication mechanisms /// if you want to implement an email-first authentication flow. /// + /// An empty `List` is returned if the user could not be found. + /// /// Errors: /// • `ERROR_INVALID_CREDENTIAL` - If the [email] address is malformed. - /// • `ERROR_USER_NOT_FOUND` - If there is no user corresponding to the given [email] address. Future> fetchSignInMethodsForEmail({ @required String email, }) async { diff --git a/packages/firebase_auth/pubspec.yaml b/packages/firebase_auth/pubspec.yaml index 90194aba4647..dbfbe9b3974f 100755 --- a/packages/firebase_auth/pubspec.yaml +++ b/packages/firebase_auth/pubspec.yaml @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS like Google, Facebook and Twitter. author: Flutter Team homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth -version: 0.14.0+4 +version: 0.14.0+5 flutter: plugin: