From 030c996889b8f43e7edc8fced3482405070c4fd1 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 11:24:21 -0700 Subject: [PATCH 1/5] Add integration test, move coalescing to native side --- packages/firebase_auth/example/test/firebase_auth.dart | 10 ++++++++++ .../firebase_auth/ios/Classes/FirebaseAuthPlugin.m | 6 +++++- packages/firebase_auth/lib/src/firebase_auth.dart | 9 +++++---- packages/firebase_auth/pubspec.yaml | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index ab969daaf2e4..1df4935efbaa 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -83,6 +83,9 @@ void main() { password: testPassword, ); expect(result.user.uid, equals(user.uid)); + List methods = await auth.fetchSignInMethodsForEmail(email: testEmail); + expect(methods.length, 1); + expect(methods[0], 'password'); await user.delete(); }); @@ -97,5 +100,12 @@ void main() { expect(await auth.isSignInWithEmailLink(emailLink2), false); expect(await auth.isSignInWithEmailLink(emailLink3), false); }); + + test('fetchSignInMethodsForEmail nonexistent user', () async { + String testEmail = 'testuser${Uuid().v4()}@example.com'; + 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..a8a4bd0ef375 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 + // to an empty array. + // 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..626d230cbf3a 100644 --- a/packages/firebase_auth/lib/src/firebase_auth.dart +++ b/packages/firebase_auth/lib/src/firebase_auth.dart @@ -109,17 +109,18 @@ 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 { assert(email != null); return await channel.invokeListMethod( - 'fetchSignInMethodsForEmail', - {'email': email, 'app': app.name}, - ); + 'fetchSignInMethodsForEmail', + {'email': email, 'app': app.name}, + ); } /// Triggers the Firebase Authentication backend to send a password-reset 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: From 5077db81ab2e9cc30d93c10d85ddd64215bb319a Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 11:31:10 -0700 Subject: [PATCH 2/5] CHANGELOG --- packages/firebase_auth/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) 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. From 74e3154b2d9cef3d98646ab82f337d8ad2dfdaa8 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 11:32:07 -0700 Subject: [PATCH 3/5] Update comment --- packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index a8a4bd0ef375..0700f7489d5f 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -133,7 +133,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(NSArray *providers, NSError *error) { // For unrecognized emails, the Auth iOS SDK should return an // empty `NSArray` here, but instead returns `nil`, so we coalesce - // to an empty array. + // with an empty `NSArray`. // https://github.com/firebase/firebase-ios-sdk/issues/3655 [self sendResult:result forObject:providers ?: @[] error:error]; }]; From b381adec5a3344bcae48b7a4cdc4f7cb4e35ce90 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Mon, 26 Aug 2019 07:32:51 -0700 Subject: [PATCH 4/5] Fix analyzer failures + reformat --- packages/firebase_auth/example/test/firebase_auth.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/firebase_auth/example/test/firebase_auth.dart b/packages/firebase_auth/example/test/firebase_auth.dart index 1df4935efbaa..52545e1e72b7 100644 --- a/packages/firebase_auth/example/test/firebase_auth.dart +++ b/packages/firebase_auth/example/test/firebase_auth.dart @@ -83,7 +83,8 @@ void main() { password: testPassword, ); expect(result.user.uid, equals(user.uid)); - List methods = await auth.fetchSignInMethodsForEmail(email: testEmail); + final List methods = + await auth.fetchSignInMethodsForEmail(email: testEmail); expect(methods.length, 1); expect(methods[0], 'password'); await user.delete(); @@ -102,8 +103,9 @@ void main() { }); test('fetchSignInMethodsForEmail nonexistent user', () async { - String testEmail = 'testuser${Uuid().v4()}@example.com'; - List methods = await auth.fetchSignInMethodsForEmail(email: testEmail); + final String testEmail = 'testuser${Uuid().v4()}@example.com'; + final List methods = + await auth.fetchSignInMethodsForEmail(email: testEmail); expect(methods, isNotNull); expect(methods.length, 0); }); From c1dc78b16cc1f9f48bcc378348049eccf362234d Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Mon, 26 Aug 2019 09:46:02 -0700 Subject: [PATCH 5/5] reformat --- packages/firebase_auth/lib/src/firebase_auth.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_auth/lib/src/firebase_auth.dart b/packages/firebase_auth/lib/src/firebase_auth.dart index 626d230cbf3a..567664be268a 100644 --- a/packages/firebase_auth/lib/src/firebase_auth.dart +++ b/packages/firebase_auth/lib/src/firebase_auth.dart @@ -118,9 +118,9 @@ class FirebaseAuth { }) async { assert(email != null); return await channel.invokeListMethod( - 'fetchSignInMethodsForEmail', - {'email': email, 'app': app.name}, - ); + 'fetchSignInMethodsForEmail', + {'email': email, 'app': app.name}, + ); } /// Triggers the Firebase Authentication backend to send a password-reset