From 17cfbee8cafefc2e09dbb1c4ce2948a216ea63d5 Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 25 Sep 2018 15:30:55 +0100 Subject: [PATCH] [auth][android] deprecate all *AndRetrieveData* methods on auth() and User --- .../firebase/auth/RNFirebaseAuth.java | 240 ++++-------------- 1 file changed, 54 insertions(+), 186 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 a3f7af72..712c6bd9 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -222,16 +222,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { } @ReactMethod - public void signInAnonymously(String appName, final Promise promise) { - signInAnonymously(appName, promise, false); - } - - @ReactMethod - public void signInAnonymouslyAndRetrieveData(String appName, final Promise promise) { - signInAnonymously(appName, promise, true); - } - - private void signInAnonymously(String appName, final Promise promise, final boolean withData) { + private void signInAnonymously(String appName, final Promise promise) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -242,11 +233,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { @Override public void onSuccess(AuthResult authResult) { Log.d(TAG, "signInAnonymously:onComplete:success"); - if (withData) { - promiseWithAuthResult(authResult, promise); - } else { - promiseWithUser(authResult.getUser(), promise); - } + promiseWithAuthResult(authResult, promise); } }) .addOnFailureListener(new OnFailureListener() { @@ -266,31 +253,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { * @param promise */ @ReactMethod - public void createUserWithEmailAndPassword( - String appName, - final String email, - final String password, - final Promise promise - ) { - createUserWithEmailAndPassword(appName, email, password, promise, false); - } - - @ReactMethod - public void createUserAndRetrieveDataWithEmailAndPassword( - String appName, - final String email, - final String password, - final Promise promise - ) { - createUserWithEmailAndPassword(appName, email, password, promise, true); - } - private void createUserWithEmailAndPassword( String appName, final String email, final String password, - final Promise promise, - final boolean withData + final Promise promise ) { Log.d(TAG, "createUserWithEmailAndPassword"); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -302,11 +269,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { @Override public void onSuccess(AuthResult authResult) { Log.d(TAG, "createUserWithEmailAndPassword:onComplete:success"); - if (withData) { - promiseWithAuthResult(authResult, promise); - } else { - promiseWithUser(authResult.getUser(), promise); - } + promiseWithAuthResult(authResult, promise); } }) .addOnFailureListener(new OnFailureListener() { @@ -326,31 +289,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { * @param promise */ @ReactMethod - public void signInWithEmailAndPassword( - String appName, - final String email, - final String password, - final Promise promise - ) { - signInWithEmailAndPassword(appName, email, password, promise, false); - } - - @ReactMethod - public void signInAndRetrieveDataWithEmailAndPassword( - String appName, - final String email, - final String password, - final Promise promise - ) { - signInWithEmailAndPassword(appName, email, password, promise, true); - } - private void signInWithEmailAndPassword( String appName, final String email, final String password, - final Promise promise, - final boolean withData + final Promise promise ) { Log.d(TAG, "signInWithEmailAndPassword"); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -362,11 +305,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { @Override public void onSuccess(AuthResult authResult) { Log.d(TAG, "signInWithEmailAndPassword:onComplete:success"); - if (withData) { - promiseWithAuthResult(authResult, promise); - } else { - promiseWithUser(authResult.getUser(), promise); - } + promiseWithAuthResult(authResult, promise); } }) .addOnFailureListener(new OnFailureListener() { @@ -415,27 +354,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { }); } - @ReactMethod - public void signInWithCustomToken(String appName, final String token, final Promise promise) { - signInWithCustomToken(appName, token, promise, false); - } - - - @ReactMethod - public void signInAndRetrieveDataWithCustomToken( - String appName, - final String token, - final Promise promise - ) { - signInWithCustomToken(appName, token, promise, true); - } - private void signInWithCustomToken( String appName, final String token, - final Promise promise, - final boolean withData + final Promise promise ) { Log.d(TAG, "signInWithCustomToken"); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -447,11 +370,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { @Override public void onSuccess(AuthResult authResult) { Log.d(TAG, "signInWithCustomToken:onComplete:success"); - if (withData) { - promiseWithAuthResult(authResult, promise); - } else { - promiseWithUser(authResult.getUser(), promise); - } + promiseWithAuthResult(authResult, promise); } }) .addOnFailureListener(new OnFailureListener() { @@ -847,34 +766,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { } @ReactMethod - public void signInWithCredential( - String appName, - String provider, - String authToken, - String authSecret, - final Promise promise - ) { - signInWithCredential(appName, provider, authToken, authSecret, promise, false); - } - - @ReactMethod - public void signInAndRetrieveDataWithCredential( - String appName, - String provider, - String authToken, - String authSecret, - final Promise promise - ) { - signInWithCredential(appName, provider, authToken, authSecret, promise, true); - } - private void signInWithCredential( String appName, String provider, String authToken, String authSecret, - final Promise promise, - final boolean withData + final Promise promise ) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -895,16 +792,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { Log.d(TAG, "signInWithCredential:onComplete:success"); - if (withData) { - promiseWithAuthResult(task.getResult(), promise); - } else { - promiseWithUser( - task - .getResult() - .getUser(), - promise - ); - } + promiseWithAuthResult(task.getResult(), promise); } else { Exception exception = task.getException(); Log.e(TAG, "signInWithCredential:onComplete:failure", exception); @@ -1358,34 +1246,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { * @param promise */ @ReactMethod - public void linkWithCredential( + private void linkWithCredential( String appName, String provider, String authToken, String authSecret, final Promise promise - ) { - link(appName, provider, authToken, authSecret, promise, false); - } - - @ReactMethod - public void linkAndRetrieveDataWithCredential( - String appName, - String provider, - String authToken, - String authSecret, - final Promise promise - ) { - link(appName, provider, authToken, authSecret, promise, true); - } - - private void link( - String appName, - String provider, - String authToken, - String authSecret, - final Promise promise, - final boolean withData ) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -1409,13 +1275,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { Log.d(TAG, "link:onComplete:success"); - if (withData) { - promiseWithAuthResult(task.getResult(), promise); - } else { - promiseWithUser(task - .getResult() - .getUser(), promise); - } + promiseWithAuthResult(task.getResult(), promise); } else { Exception exception = task.getException(); Log.e(TAG, "link:onComplete:failure", exception); @@ -1460,34 +1320,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { } @ReactMethod - public void reauthenticateWithCredential( + private void reauthenticateWithCredential( String appName, String provider, String authToken, String authSecret, final Promise promise - ) { - reauthenticate(appName, provider, authToken, authSecret, promise, false); - } - - @ReactMethod - public void reauthenticateAndRetrieveDataWithCredential( - String appName, - String provider, - String authToken, - String authSecret, - final Promise promise - ) { - reauthenticate(appName, provider, authToken, authSecret, promise, true); - } - - private void reauthenticate( - String appName, - String provider, - String authToken, - String authSecret, - final Promise promise, - final boolean withData ) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); @@ -1511,13 +1349,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { Log.d(TAG, "reauthenticate:onComplete:success"); - if (withData) { - promiseWithAuthResult(task.getResult(), promise); - } else { - promiseWithUser(task - .getResult() - .getUser(), promise); - } + promiseWithAuthResult(task.getResult(), promise); } else { Exception exception = task.getException(); Log.e(TAG, "reauthenticate:onComplete:failure", exception); @@ -1581,9 +1413,21 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { mCredential = null; return credential; } - return PhoneAuthProvider.getCredential(authToken, authSecret); + + if (authToken != null) { + return PhoneAuthProvider.getCredential(authToken, authSecret); + } + + return null; } + /** + * getToken + * + * @param appName + * @param forceRefresh + * @param promise + */ @ReactMethod public void getToken(String appName, Boolean forceRefresh, final Promise promise) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -1615,6 +1459,13 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { } } + /** + * fetchSignInMethodsForEmail + * + * @param appName + * @param email + * @param promise + */ @ReactMethod public void fetchSignInMethodsForEmail(String appName, String email, final Promise promise) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -1650,6 +1501,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { }); } + /** + * setLanguageCode + * + * @param appName + * @param code + */ @ReactMethod public void setLanguageCode(String appName, String code) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -1658,6 +1515,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { firebaseAuth.setLanguageCode(code); } + /** + * useDeviceLanguage + * + * @param appName + */ @ReactMethod public void useDeviceLanguage(String appName) { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); @@ -1731,16 +1593,19 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { */ private void promiseWithAuthResult(AuthResult authResult, Promise promise) { if (authResult != null && authResult.getUser() != null) { - WritableMap userMap = firebaseUserToMap(authResult.getUser()); WritableMap authResultMap = Arguments.createMap(); + WritableMap userMap = firebaseUserToMap(authResult.getUser()); + if (authResult.getAdditionalUserInfo() != null) { WritableMap additionalUserInfoMap = Arguments.createMap(); + additionalUserInfoMap.putBoolean( "isNewUser", authResult .getAdditionalUserInfo() .isNewUser() ); + if (authResult .getAdditionalUserInfo() .getProfile() != null) { @@ -1752,6 +1617,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { additionalUserInfoMap ); } + if (authResult .getAdditionalUserInfo() .getProviderId() != null) { @@ -1762,6 +1628,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { .getProviderId() ); } + if (authResult .getAdditionalUserInfo() .getUsername() != null) { @@ -1772,6 +1639,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { .getUsername() ); } + authResultMap.putMap("additionalUserInfo", additionalUserInfoMap); } authResultMap.putMap("user", userMap); @@ -1911,7 +1779,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { final Uri photoUrl = userInfo.getPhotoUrl(); - if (photoUrl != null && !"".equals(photoUrl)) { + if (photoUrl != null && !"".equals(photoUrl.toString())) { userInfoMap.putString("photoURL", photoUrl.toString()); } else { userInfoMap.putNull("photoURL"); @@ -1981,7 +1849,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { userMap.putNull("displayName"); } - if (photoUrl != null && !"".equals(photoUrl)) { + if (photoUrl != null && !"".equals(photoUrl.toString())) { userMap.putString("photoURL", photoUrl.toString()); } else { userMap.putNull("photoURL");