mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
more work on multiple app initialization
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.HashMap;
|
||||
|
||||
// react
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.LifecycleEventListener;
|
||||
@@ -17,6 +18,8 @@ import com.facebook.react.bridge.ReactMethod;
|
||||
// play services
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.FirebaseOptions;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class RNFirebaseModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
|
||||
@@ -45,9 +48,22 @@ public class RNFirebaseModule extends ReactContextBaseJavaModule implements Life
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void initializeApp(String name, ReadableMap options) {
|
||||
// todo https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseOptions
|
||||
public void initializeApp(String name, ReadableMap options, Callback callback) {
|
||||
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
|
||||
|
||||
builder.setApplicationId(options.getString("androidAppId"));
|
||||
builder.setGcmSenderId(options.getString("messagingSenderId"));
|
||||
builder.setApiKey(options.getString("apiKey"));
|
||||
builder.setProjectId(options.getString("projectId"));
|
||||
builder.setDatabaseUrl(options.getString("databaseURL"));
|
||||
builder.setStorageBucket(options.getString("storageBucket"));
|
||||
|
||||
FirebaseApp.initializeApp(getReactApplicationContext(), builder.build(), name);
|
||||
|
||||
// todo expand on callback result
|
||||
WritableMap response = Arguments.createMap();
|
||||
response.putString("result", "success");
|
||||
callback.invoke(null, response);
|
||||
}
|
||||
|
||||
private WritableMap getPlayServicesStatus() {
|
||||
|
||||
@@ -4,8 +4,8 @@ import android.util.Log;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.auth.AuthCredential;
|
||||
import com.google.firebase.auth.AuthResult;
|
||||
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
|
||||
@@ -46,14 +47,16 @@ import io.invertase.firebase.Utils;
|
||||
class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
private static final String TAG = "RNFirebaseAuth";
|
||||
|
||||
// itts been a while ;p
|
||||
|
||||
|
||||
private ReactContext mReactContext;
|
||||
private FirebaseAuth mAuth;
|
||||
private Map<String, FirebaseAuth.AuthStateListener> mAuthListeners;
|
||||
private HashMap<String, FirebaseAuth.AuthStateListener> mAuthListeners = new HashMap<>();
|
||||
|
||||
|
||||
RNFirebaseAuth(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
mReactContext = reactContext;
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
Log.d(TAG, "RNFirebaseAuth:initialized");
|
||||
}
|
||||
|
||||
@@ -68,6 +71,10 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
@ReactMethod
|
||||
public void addAuthStateListener(final String appName) {
|
||||
Log.d(TAG, "addAuthStateListener");
|
||||
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseAuth.AuthStateListener mAuthListener = mAuthListeners.get(appName);
|
||||
if (mAuthListener == null) {
|
||||
FirebaseAuth.AuthStateListener newAuthListener = new FirebaseAuth.AuthStateListener() {
|
||||
@@ -87,7 +94,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
}
|
||||
};
|
||||
|
||||
mAuth.addAuthStateListener(newAuthListener);
|
||||
firebaseAuth.addAuthStateListener(newAuthListener);
|
||||
mAuthListeners.put(appName, newAuthListener);
|
||||
}
|
||||
}
|
||||
@@ -98,10 +105,15 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
@ReactMethod
|
||||
public void removeAuthStateListener(String appName) {
|
||||
Log.d(TAG, "removeAuthStateListener");
|
||||
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseAuth.AuthStateListener mAuthListener = mAuthListeners.get(appName);
|
||||
|
||||
if (mAuthListener != null) {
|
||||
mAuth.removeAuthStateListener(mAuthListener);
|
||||
firebaseAuth.removeAuthStateListener(mAuthListener);
|
||||
mAuthListeners.remove(appName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,12 +123,15 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void signOut(final Promise promise) {
|
||||
public void signOut(String appName, Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
Log.d(TAG, "signOut");
|
||||
if (mAuth == null || mAuth.getCurrentUser() == null) {
|
||||
if (firebaseAuth == null || firebaseAuth.getCurrentUser() == null) {
|
||||
promiseNoUser(promise, true);
|
||||
} else {
|
||||
mAuth.signOut();
|
||||
firebaseAuth.signOut();
|
||||
promiseNoUser(promise, false);
|
||||
}
|
||||
}
|
||||
@@ -127,9 +142,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void signInAnonymously(final Promise promise) {
|
||||
public void signInAnonymously(String appName, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
Log.d(TAG, "signInAnonymously");
|
||||
mAuth.signInAnonymously()
|
||||
firebaseAuth.signInAnonymously()
|
||||
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
|
||||
@Override
|
||||
public void onSuccess(AuthResult authResult) {
|
||||
@@ -154,9 +172,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void createUserWithEmailAndPassword(final String email, final String password, final Promise promise) {
|
||||
public void createUserWithEmailAndPassword(String appName, final String email, final String password, final Promise promise) {
|
||||
Log.d(TAG, "createUserWithEmailAndPassword");
|
||||
mAuth.createUserWithEmailAndPassword(email, password)
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
firebaseAuth.createUserWithEmailAndPassword(email, password)
|
||||
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
|
||||
@Override
|
||||
public void onSuccess(AuthResult authResult) {
|
||||
@@ -181,9 +202,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void signInWithEmailAndPassword(final String email, final String password, final Promise promise) {
|
||||
public void signInWithEmailAndPassword(String appName, final String email, final String password, final Promise promise) {
|
||||
Log.d(TAG, "signInWithEmailAndPassword");
|
||||
mAuth.signInWithEmailAndPassword(email, password)
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
firebaseAuth.signInWithEmailAndPassword(email, password)
|
||||
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
|
||||
@Override
|
||||
public void onSuccess(AuthResult authResult) {
|
||||
@@ -208,9 +232,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void signInWithCustomToken(final String token, final Promise promise) {
|
||||
public void signInWithCustomToken(String appName, final String token, final Promise promise) {
|
||||
Log.d(TAG, "signInWithCustomToken");
|
||||
mAuth.signInWithCustomToken(token)
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
firebaseAuth.signInWithCustomToken(token)
|
||||
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
|
||||
@Override
|
||||
public void onSuccess(AuthResult authResult) {
|
||||
@@ -234,9 +261,12 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void sendPasswordResetEmail(final String email, final Promise promise) {
|
||||
public void sendPasswordResetEmail(String appName, final String email, final Promise promise) {
|
||||
Log.d(TAG, "sendPasswordResetEmail");
|
||||
mAuth.sendPasswordResetEmail(email)
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
firebaseAuth.sendPasswordResetEmail(email)
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
@@ -259,8 +289,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void getCurrentUser(final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void getCurrentUser(String appName, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "getCurrentUser");
|
||||
if (user == null) {
|
||||
promiseNoUser(promise, false);
|
||||
@@ -279,8 +312,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void delete(final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void delete(String appName, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "delete");
|
||||
if (user != null) {
|
||||
user.delete()
|
||||
@@ -309,8 +345,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void reload(final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void reload(String appName, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "reload");
|
||||
|
||||
if (user == null) {
|
||||
@@ -323,7 +362,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d(TAG, "reload:onComplete:success");
|
||||
promiseWithUser(mAuth.getCurrentUser(), promise);
|
||||
promiseWithUser(firebaseAuth.getCurrentUser(), promise);
|
||||
} else {
|
||||
Exception exception = task.getException();
|
||||
Log.e(TAG, "reload:onComplete:failure", exception);
|
||||
@@ -340,8 +379,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void sendEmailVerification(final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void sendEmailVerification(String appName, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "sendEmailVerification");
|
||||
|
||||
if (user == null) {
|
||||
@@ -354,7 +396,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d(TAG, "sendEmailVerification:onComplete:success");
|
||||
promiseWithUser(mAuth.getCurrentUser(), promise);
|
||||
promiseWithUser(firebaseAuth.getCurrentUser(), promise);
|
||||
} else {
|
||||
Exception exception = task.getException();
|
||||
Log.e(TAG, "sendEmailVerification:onComplete:failure", exception);
|
||||
@@ -372,8 +414,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void updateEmail(final String email, final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void updateEmail(String appName, final String email, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "updateEmail");
|
||||
|
||||
if (user == null) {
|
||||
@@ -386,7 +431,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d(TAG, "updateEmail:onComplete:success");
|
||||
promiseWithUser(mAuth.getCurrentUser(), promise);
|
||||
promiseWithUser(firebaseAuth.getCurrentUser(), promise);
|
||||
} else {
|
||||
Exception exception = task.getException();
|
||||
Log.e(TAG, "updateEmail:onComplete:failure", exception);
|
||||
@@ -404,8 +449,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void updatePassword(final String password, final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void updatePassword(String appName, final String password, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "updatePassword");
|
||||
|
||||
if (user == null) {
|
||||
@@ -418,7 +466,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d(TAG, "updatePassword:onComplete:success");
|
||||
promiseWithUser(mAuth.getCurrentUser(), promise);
|
||||
promiseWithUser(firebaseAuth.getCurrentUser(), promise);
|
||||
} else {
|
||||
Exception exception = task.getException();
|
||||
Log.e(TAG, "updatePassword:onComplete:failure", exception);
|
||||
@@ -436,8 +484,11 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void updateProfile(ReadableMap props, final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
public void updateProfile(String appName, ReadableMap props, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "updateProfile");
|
||||
|
||||
if (user == null) {
|
||||
@@ -465,7 +516,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d(TAG, "updateProfile:onComplete:success");
|
||||
promiseWithUser(mAuth.getCurrentUser(), promise);
|
||||
promiseWithUser(firebaseAuth.getCurrentUser(), promise);
|
||||
} else {
|
||||
Exception exception = task.getException();
|
||||
Log.e(TAG, "updateProfile:onComplete:failure", exception);
|
||||
@@ -485,14 +536,17 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void signInWithCredential(final String provider, final String authToken, final String authSecret, final Promise promise) {
|
||||
public void signInWithCredential(String appName, String provider, String authToken, String authSecret, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
AuthCredential credential = getCredentialForProvider(provider, authToken, authSecret);
|
||||
|
||||
if (credential == null) {
|
||||
promise.reject("auth/invalid-credential", "The supplied auth credential is malformed, has expired or is not currently supported.");
|
||||
} else {
|
||||
Log.d(TAG, "signInWithCredential");
|
||||
mAuth.signInWithCredential(credential)
|
||||
firebaseAuth.signInWithCredential(credential)
|
||||
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
@@ -518,13 +572,16 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void link(final String provider, final String authToken, final String authSecret, final Promise promise) {
|
||||
public void link(String appName, String provider, String authToken, String authSecret, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
AuthCredential credential = getCredentialForProvider(provider, authToken, authSecret);
|
||||
|
||||
if (credential == null) {
|
||||
promise.reject("auth/invalid-credential", "The supplied auth credential is malformed, has expired or is not currently supported.");
|
||||
} else {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "link");
|
||||
|
||||
if (user != null) {
|
||||
@@ -557,13 +614,16 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void reauthenticate(final String provider, final String authToken, final String authSecret, final Promise promise) {
|
||||
public void reauthenticate(String appName, String provider, String authToken, String authSecret, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
AuthCredential credential = getCredentialForProvider(provider, authToken, authSecret);
|
||||
|
||||
if (credential == null) {
|
||||
promise.reject("auth/invalid-credential", "The supplied auth credential is malformed, has expired or is not currently supported.");
|
||||
} else {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "reauthenticate");
|
||||
|
||||
if (user != null) {
|
||||
@@ -573,7 +633,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d(TAG, "reauthenticate:onComplete:success");
|
||||
promiseWithUser(mAuth.getCurrentUser(), promise);
|
||||
promiseWithUser(firebaseAuth.getCurrentUser(), promise);
|
||||
} else {
|
||||
Exception exception = task.getException();
|
||||
Log.e(TAG, "reauthenticate:onComplete:failure", exception);
|
||||
@@ -595,7 +655,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param authSecret
|
||||
* @return
|
||||
*/
|
||||
public AuthCredential getCredentialForProvider(String provider, String authToken, String authSecret) {
|
||||
private AuthCredential getCredentialForProvider(String provider, String authToken, String authSecret) {
|
||||
switch (provider) {
|
||||
case "facebook":
|
||||
return FacebookAuthProvider.getCredential(authToken);
|
||||
@@ -618,12 +678,15 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void getToken(final Boolean forceRefresh, final Promise promise) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
Log.d(TAG, "getToken");
|
||||
public void getToken(String appName, Boolean forceRefresh, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
Log.d(TAG, "getToken/getIdToken");
|
||||
|
||||
if (user != null) {
|
||||
user.getToken(forceRefresh)
|
||||
user.getIdToken(forceRefresh)
|
||||
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<GetTokenResult> task) {
|
||||
@@ -648,10 +711,13 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void fetchProvidersForEmail(final String email, final Promise promise) {
|
||||
public void fetchProvidersForEmail(String appName, String email, final Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
|
||||
Log.d(TAG, "fetchProvidersForEmail");
|
||||
|
||||
mAuth.fetchProvidersForEmail(email)
|
||||
firebaseAuth.fetchProvidersForEmail(email)
|
||||
.addOnCompleteListener(new OnCompleteListener<ProviderQueryResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<ProviderQueryResult> task) {
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
package io.invertase.firebase.config;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchException;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
import io.invertase.firebase.Utils;
|
||||
|
||||
public class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
||||
class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
||||
|
||||
private static final String TAG = "RNFirebaseRemoteConfig";
|
||||
|
||||
@@ -37,7 +34,7 @@ public class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
||||
private static final String NUMBER_VALUE = "numberValue";
|
||||
private static final String SOURCE = "source";
|
||||
|
||||
public RNFirebaseRemoteConfig(ReactApplicationContext reactContext) {
|
||||
RNFirebaseRemoteConfig(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
Log.d(TAG, "New instance");
|
||||
}
|
||||
@@ -51,7 +48,7 @@ public class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void enableDeveloperMode() {
|
||||
public void enableDeveloperMode(String appName) {
|
||||
FirebaseRemoteConfigSettings.Builder settings = new FirebaseRemoteConfigSettings.Builder();
|
||||
settings.setDeveloperModeEnabled(true);
|
||||
FirebaseRemoteConfig.getInstance().setConfigSettings(settings.build());
|
||||
|
||||
Reference in New Issue
Block a user