Add support to reload firebase user (#533)
diff --git a/AUTHORS b/AUTHORS index 590246c..b524c5c 100644 --- a/AUTHORS +++ b/AUTHORS
@@ -11,3 +11,4 @@ Pol Batlló <pol.batllo@gmail.com> Anatoly Pulyaevskiy Stefano Rodriguez <hlsroddy@gmail.com> +Salvatore Giordano <salvatoregiordanoo@gmail.com>
diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index 3746073..27acf4f 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md
@@ -1,3 +1,7 @@ +## 0.5.8 + +* Added support to reload firebase user + ## 0.5.7 * Added support to sendEmailVerification
diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java index 489b5fb..62d5a88 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java
@@ -68,6 +68,9 @@ case "sendEmailVerification": handleSendEmailVerification(call, result); break; + case "reload": + handleReload(call, result); + break; case "signInWithEmailAndPassword": handleSignInWithEmailAndPassword(call, result); break; @@ -180,6 +183,13 @@ .addOnCompleteListener(new TaskVoidCompleteListener(result)); } + private void handleReload(MethodCall call, final Result result) { + firebaseAuth + .getCurrentUser() + .reload() + .addOnCompleteListener(new TaskVoidCompleteListener(result)); + } + private void handleSignInWithEmailAndPassword(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map<String, String> arguments = (Map<String, String>) call.arguments;
diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index e2798e2..307fd49 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
@@ -103,7 +103,10 @@ [[FIRAuth auth].currentUser sendEmailVerificationWithCompletion:^(NSError *_Nullable error) { [self sendResult:result forProviders:nil error:error]; }]; - + } else if ([@"reload" isEqualToString:call.method]) { + [[FIRAuth auth].currentUser reloadWithCompletion:^(NSError *_Nullable error) { + [self sendResult:result forProviders:nil error:error]; + }]; } else if ([@"sendPasswordResetEmail" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; [[FIRAuth auth] sendPasswordResetWithEmail:email
diff --git a/packages/firebase_auth/lib/firebase_auth.dart b/packages/firebase_auth/lib/firebase_auth.dart index a314728..8a83995 100755 --- a/packages/firebase_auth/lib/firebase_auth.dart +++ b/packages/firebase_auth/lib/firebase_auth.dart
@@ -82,6 +82,11 @@ await FirebaseAuth.channel.invokeMethod('sendEmailVerification'); } + /// Manually refreshes the data of the current user (for example, attached providers, display name, and so on). + Future<void> reload() async { + await FirebaseAuth.channel.invokeMethod('reload'); + } + @override String toString() { return '$runtimeType($_data)';
diff --git a/packages/firebase_auth/pubspec.yaml b/packages/firebase_auth/pubspec.yaml index 84a0c09..fe965bb 100755 --- a/packages/firebase_auth/pubspec.yaml +++ b/packages/firebase_auth/pubspec.yaml
@@ -4,7 +4,7 @@ and Twitter. author: Flutter Team <flutter-dev@googlegroups.com> homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth -version: 0.5.7 +version: 0.5.8 flutter: plugin:
diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 76cb57c..126b698 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart
@@ -265,6 +265,25 @@ ); }); + test('reload', () async { + final FirebaseUser user = await auth.currentUser(); + await user.reload(); + + expect( + log, + <Matcher>[ + isMethodCall( + 'currentUser', + arguments: null, + ), + isMethodCall( + 'reload', + arguments: null, + ), + ], + ); + }); + test('sendPasswordResetEmail', () async { await auth.sendPasswordResetEmail( email: kMockEmail,