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

[firebase_auth] Consistent platform behavior for fetchSignInMethodsForEmail #26

Merged
merged 6 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
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
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 <[email protected]>
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