[android] start of auth().currentUser methods refactor

This commit is contained in:
Salakar 2017-03-15 20:17:04 +00:00
parent a780f9677d
commit afece365e4
2 changed files with 41 additions and 34 deletions

View File

@ -267,6 +267,10 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
} }
} }
/* ----------------------
* .currentUser methods
* ---------------------- */
/** /**
* delete * delete
* *
@ -293,11 +297,43 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
} }
}); });
} else { } else {
Log.e(TAG, "signInWithCustomToken:onComplete:failure:noCurrentUser"); Log.e(TAG, "delete:failure:noCurrentUser");
promiseNoUser(promise, true); 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<Void>() {
@Override
public void onComplete(@NonNull Task<Void> 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 * 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<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "user reloaded");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
}
});
}
}
// TODO: Check these things // TODO: Check these things
@ReactMethod @ReactMethod
public void googleLogin(String IdToken, final Callback callback) { public void googleLogin(String IdToken, final Callback callback) {
@ -636,6 +650,8 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
/** /**
* firebaseUserToMap
*
* @param user * @param user
* @return * @return
*/ */

View File

@ -102,15 +102,6 @@ export default class User {
toJSON() { toJSON() {
return Object.assign({}, this._user); 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} * @return {Promise}
*/ */
delete(): Promise<Object> { delete(): Promise<Object> {
return FirebaseAuth.delete(); return this._auth._interceptUserValue(FirebaseAuth.delete());
} }
/** /**
@ -126,7 +117,7 @@ export default class User {
* @return {Promise} * @return {Promise}
*/ */
reload(): Promise<Object> { reload(): Promise<Object> {
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. // TODO no RN android method yet, the SDK does have .getProviderData but returns as a List.