Skip to content

Commit

Permalink
Merge pull request #26 from collinjackson/flutter/plugins#2002
Browse files Browse the repository at this point in the history
[firebase_auth] Consistent platform behavior for fetchSignInMethodsForEmail
  • Loading branch information
kroikie authored Aug 30, 2019
2 parents 08dad0c + c1dc78b commit 14c3eab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 12 additions & 0 deletions packages/firebase_auth/example/test/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ void main() {
password: testPassword,
);
expect(result.user.uid, equals(user.uid));
final List<String> methods =
await auth.fetchSignInMethodsForEmail(email: testEmail);
expect(methods.length, 1);
expect(methods[0], 'password');
await user.delete();
});

Expand All @@ -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<String> methods =
await auth.fetchSignInMethodsForEmail(email: testEmail);
expect(methods, isNotNull);
expect(methods.length, 0);
});
});
}
6 changes: 5 additions & 1 deletion packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[[self getAuth:call.arguments]
fetchProvidersForEmail:email
completion:^(NSArray<NSString *> *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
Expand Down
3 changes: 2 additions & 1 deletion packages/firebase_auth/lib/src/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<String>> fetchSignInMethodsForEmail({
@required String email,
}) async {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
like Google, Facebook and Twitter.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth
version: 0.14.0+4
version: 0.14.0+5

flutter:
plugin:
Expand Down

0 comments on commit 14c3eab

Please sign in to comment.