From afece365e403484112e29fafd6c1423484195896 Mon Sep 17 00:00:00 2001 From: Salakar Date: Wed, 15 Mar 2017 20:17:04 +0000 Subject: [PATCH] [android] start of auth().currentUser methods refactor --- .../firebase/auth/RNFirebaseAuth.java | 62 ++++++++++++------- lib/modules/auth/user.js | 13 +--- 2 files changed, 41 insertions(+), 34 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 0ade1d2b..5fed18e9 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -267,6 +267,10 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { } } + /* ---------------------- + * .currentUser methods + * ---------------------- */ + /** * delete * @@ -293,11 +297,43 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { } }); } else { - Log.e(TAG, "signInWithCustomToken:onComplete:failure:noCurrentUser"); + Log.e(TAG, "delete:failure:noCurrentUser"); promiseNoUser(promise, true); } } + /** + * reload + * + * @param promise + */ + @ReactMethod + public void reload(final Promise promise) { + FirebaseUser user = mAuth.getCurrentUser(); + Log.d(TAG, "delete"); + + if (user == null) { + promiseNoUser(promise, false); + Log.e(TAG, "reload:failure:noCurrentUser"); + } else { + user.reload() + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) { + Log.d(TAG, "reload:onComplete:success"); + promiseWithUser(mAuth.getCurrentUser(), promise); + } else { + Exception exception = task.getException(); + WritableMap error = authExceptionToMap(exception); + Log.e(TAG, "reload:onComplete:failure", exception); + promise.reject(error.getString("code"), error.getString("message"), exception); + } + } + }); + } + } + /** * signInWithCredential @@ -538,28 +574,6 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { } - @ReactMethod - public void reload(final Callback callback) { - FirebaseUser user = mAuth.getCurrentUser(); - - if (user == null) { - callbackNoUser(callback, false); - } else { - user.reload() - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - if (task.isSuccessful()) { - Log.d(TAG, "user reloaded"); - userCallback(mAuth.getCurrentUser(), callback); - } else { - userErrorCallback(task, callback); - } - } - }); - } - } - // TODO: Check these things @ReactMethod public void googleLogin(String IdToken, final Callback callback) { @@ -636,6 +650,8 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { /** + * firebaseUserToMap + * * @param user * @return */ diff --git a/lib/modules/auth/user.js b/lib/modules/auth/user.js index 40d64dbc..cff97aa5 100644 --- a/lib/modules/auth/user.js +++ b/lib/modules/auth/user.js @@ -102,15 +102,6 @@ export default class User { toJSON() { return Object.assign({}, this._user); - return { - uid: this.uid, - email: this.email, - emailVerified: this.emailVerified, - displayName: this.displayName, - providerId: this.providerId, - isAnonymous: this.isAnonymous, - photoURL: this.photoURL, - }; } /** @@ -118,7 +109,7 @@ export default class User { * @return {Promise} */ delete(): Promise { - return FirebaseAuth.delete(); + return this._auth._interceptUserValue(FirebaseAuth.delete()); } /** @@ -126,7 +117,7 @@ export default class User { * @return {Promise} */ reload(): Promise { - return promisify('reload', FirebaseAuth, 'auth/')(); + return this._auth._interceptUserValue(FirebaseAuth.reload()); } // TODO no RN android method yet, the SDK does have .getProviderData but returns as a List.