Skip to content

Commit 14c3eab

Browse files
authored
Merge pull request flutter#26 from collinjackson/flutter#2002
[firebase_auth] Consistent platform behavior for fetchSignInMethodsForEmail
2 parents 08dad0c + c1dc78b commit 14c3eab

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

packages/firebase_auth/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.14.0+5
2+
3+
* On iOS, `fetchSignInMethodsForEmail` now returns an empty list when the email
4+
cannot be found, matching the Android behavior.
5+
16
## 0.14.0+4
27

38
* Fixed "Register a user" example code snippet in README.md.

packages/firebase_auth/example/test/firebase_auth.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ void main() {
8383
password: testPassword,
8484
);
8585
expect(result.user.uid, equals(user.uid));
86+
final List<String> methods =
87+
await auth.fetchSignInMethodsForEmail(email: testEmail);
88+
expect(methods.length, 1);
89+
expect(methods[0], 'password');
8690
await user.delete();
8791
});
8892

@@ -97,5 +101,13 @@ void main() {
97101
expect(await auth.isSignInWithEmailLink(emailLink2), false);
98102
expect(await auth.isSignInWithEmailLink(emailLink3), false);
99103
});
104+
105+
test('fetchSignInMethodsForEmail nonexistent user', () async {
106+
final String testEmail = 'testuser${Uuid().v4()}@example.com';
107+
final List<String> methods =
108+
await auth.fetchSignInMethodsForEmail(email: testEmail);
109+
expect(methods, isNotNull);
110+
expect(methods.length, 0);
111+
});
100112
});
101113
}

packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
131131
[[self getAuth:call.arguments]
132132
fetchProvidersForEmail:email
133133
completion:^(NSArray<NSString *> *providers, NSError *error) {
134-
[self sendResult:result forObject:providers error:error];
134+
// For unrecognized emails, the Auth iOS SDK should return an
135+
// empty `NSArray` here, but instead returns `nil`, so we coalesce
136+
// with an empty `NSArray`.
137+
// https://github.com/firebase/firebase-ios-sdk/issues/3655
138+
[self sendResult:result forObject:providers ?: @[] error:error];
135139
}];
136140
} else if ([@"sendEmailVerification" isEqualToString:call.method]) {
137141
[[self getAuth:call.arguments].currentUser

packages/firebase_auth/lib/src/firebase_auth.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ class FirebaseAuth {
109109
/// This method is useful when you support multiple authentication mechanisms
110110
/// if you want to implement an email-first authentication flow.
111111
///
112+
/// An empty `List` is returned if the user could not be found.
113+
///
112114
/// Errors:
113115
/// • `ERROR_INVALID_CREDENTIAL` - If the [email] address is malformed.
114-
/// • `ERROR_USER_NOT_FOUND` - If there is no user corresponding to the given [email] address.
115116
Future<List<String>> fetchSignInMethodsForEmail({
116117
@required String email,
117118
}) async {

packages/firebase_auth/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
44
like Google, Facebook and Twitter.
55
author: Flutter Team <[email protected]>
66
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth
7-
version: 0.14.0+4
7+
version: 0.14.0+5
88

99
flutter:
1010
plugin:

0 commit comments

Comments
 (0)