From 8d45bfdbf43ab71e1304038996ffdd531a89bf3d Mon Sep 17 00:00:00 2001 From: Salakar Date: Sat, 18 Mar 2017 00:40:55 +0000 Subject: [PATCH] [android][auth] implemented currentUser.updatePassword() method --- .../firebase/auth/RNFirebaseAuth.java | 88 +++++++------------ 1 file changed, 34 insertions(+), 54 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java index 9af30784..f9076e90 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -361,6 +361,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { /** * updateEmail * + * @param email * @param promise */ @ReactMethod @@ -389,6 +390,38 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { } } + /** + * updatePassword + * + * @param password + * @param promise + */ + @ReactMethod + public void updatePassword(final String password, final Promise promise) { + FirebaseUser user = mAuth.getCurrentUser(); + Log.d(TAG, "updatePassword"); + + if (user == null) { + promiseNoUser(promise, false); + Log.e(TAG, "updatePassword:failure:noCurrentUser"); + } else { + user.updatePassword(password) + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) { + Log.d(TAG, "updatePassword:onComplete:success"); + promiseWithUser(mAuth.getCurrentUser(), promise); + } else { + Exception exception = task.getException(); + Log.e(TAG, "updatePassword:onComplete:failure", exception); + promiseRejectAuthException(promise, exception); + } + } + }); + } + } + /** * signInWithCredential * @@ -566,60 +599,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { // ----------------------- CLEAN ME ----------------------------------------------------- // ----------------------- CLEAN ME ----------------------------------------------------- - @ReactMethod - public void updateUserEmail(final String email, final Callback callback) { - FirebaseUser user = mAuth.getCurrentUser(); - - if (user != null) { - user - .updateEmail(email) - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - try { - if (task.isSuccessful()) { - Log.d(TAG, "User email address updated"); - userCallback(mAuth.getCurrentUser(), callback); - } else { - userErrorCallback(task, callback); - } - } catch (Exception ex) { - userExceptionCallback(ex, callback); - } - } - }); - } else { - callbackNoUser(callback, true); - } - } - - @ReactMethod - public void updateUserPassword(final String newPassword, final Callback callback) { - FirebaseUser user = mAuth.getCurrentUser(); - - if (user != null) { - user.updatePassword(newPassword) - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - try { - if (task.isSuccessful()) { - Log.d(TAG, "User password updated"); - userCallback(mAuth.getCurrentUser(), callback); - } else { - userErrorCallback(task, callback); - } - } catch (Exception ex) { - userExceptionCallback(ex, callback); - } - } - }); - } else { - callbackNoUser(callback, true); - } - } - - @ReactMethod + @ReactMethod public void updateUserProfile(ReadableMap props, final Callback callback) { FirebaseUser user = mAuth.getCurrentUser();