46
46
import com .google .firebase .auth .FirebaseAuth ;
47
47
import com .google .firebase .auth .FirebaseAuthException ;
48
48
import com .google .firebase .auth .FirebaseAuthInvalidCredentialsException ;
49
+ import com .google .firebase .auth .FirebaseAuthUserCollisionException ;
49
50
import com .google .firebase .auth .FirebaseAuthMultiFactorException ;
50
51
import com .google .firebase .auth .FirebaseAuthProvider ;
51
52
import com .google .firebase .auth .FirebaseAuthSettings ;
@@ -845,9 +846,12 @@ private void signInWithCredential(
845
846
@ ReactMethod
846
847
public void signInWithProvider (String appName , String providerId , @ Nullable String email , Promise promise ){
847
848
OAuthProvider .Builder provider = OAuthProvider .newBuilder (providerId );
849
+
848
850
if (email != null ){
849
851
provider .addCustomParameter ("login_hint" , email );
850
852
}
853
+ provider .addCustomParameter ("prompt" , "select_account" );
854
+
851
855
Activity activity = getCurrentActivity ();
852
856
FirebaseApp firebaseApp = FirebaseApp .getInstance (appName );
853
857
FirebaseAuth firebaseAuth = FirebaseAuth .getInstance (firebaseApp );
@@ -885,9 +889,12 @@ public void onFailure(@NonNull Exception e) {
885
889
@ ReactMethod
886
890
public void linkWithProvider (String appName , String providerId , @ Nullable String email , Promise promise ){
887
891
OAuthProvider .Builder provider = OAuthProvider .newBuilder (providerId );
892
+
888
893
if (email != null ){
889
894
provider .addCustomParameter ("login_hint" , email );
890
895
}
896
+ provider .addCustomParameter ("prompt" , "select_account" );
897
+
891
898
Activity activity = getCurrentActivity ();
892
899
FirebaseApp firebaseApp = FirebaseApp .getInstance (appName );
893
900
FirebaseAuth firebaseAuth = FirebaseAuth .getInstance (firebaseApp );
@@ -1954,7 +1961,7 @@ private void promiseWithAuthResult(AuthResult authResult, Promise promise) {
1954
1961
if (authResult .getCredential () instanceof OAuthCredential ){
1955
1962
OAuthCredential creds = (OAuthCredential ) authResult .getCredential ();
1956
1963
WritableMap credentialMap = Arguments .createMap ();
1957
-
1964
+
1958
1965
credentialMap .putString ("providerId" , creds .getProvider ());
1959
1966
credentialMap .putString ("signInMethod" , creds .getSignInMethod ());
1960
1967
@@ -2014,15 +2021,23 @@ private void promiseWithAuthResult(AuthResult authResult, Promise promise) {
2014
2021
*/
2015
2022
private void promiseRejectAuthException (Promise promise , Exception exception ) {
2016
2023
WritableMap error = getJSError (exception );
2017
-
2024
+
2018
2025
final String sessionId = error .getString ("sessionId" );
2019
2026
final MultiFactorResolver multiFactorResolver = mCachedResolvers .get (sessionId );
2020
2027
WritableMap resolverAsMap = Arguments .createMap ();
2028
+
2029
+ WritableMap map = Arguments .createMap ();
2021
2030
if (multiFactorResolver != null ) {
2022
2031
resolverAsMap = resolverToMap (sessionId , multiFactorResolver );
2032
+ map .putMap ("resolver" , resolverAsMap );
2023
2033
}
2024
- rejectPromiseWithCodeAndMessage (
2025
- promise , error .getString ("code" ), error .getString ("message" ), resolverAsMap );
2034
+
2035
+ if (error .getString ("email" ) != null ){
2036
+ map .putString ("email" , error .getString ("email" ));
2037
+ }
2038
+
2039
+ rejectPromiseWithMap (
2040
+ promise , error .getString ("code" ), error .getString ("message" ), map );
2026
2041
}
2027
2042
2028
2043
/**
@@ -2037,7 +2052,6 @@ private WritableMap getJSError(Exception exception) {
2037
2052
String invalidEmail = "The email address is badly formatted." ;
2038
2053
2039
2054
System .out .print (exception );
2040
-
2041
2055
try {
2042
2056
FirebaseAuthException authException = (FirebaseAuthException ) exception ;
2043
2057
code = authException .getErrorCode ();
@@ -2073,7 +2087,7 @@ private WritableMap getJSError(Exception exception) {
2073
2087
+ " before retrying this request." ;
2074
2088
break ;
2075
2089
case "ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL" :
2076
- message =
2090
+ message =
2077
2091
"An account already exists with the same email address but different sign-in"
2078
2092
+ " credentials. Sign in using a provider associated with this email address." ;
2079
2093
break ;
@@ -2111,6 +2125,10 @@ private WritableMap getJSError(Exception exception) {
2111
2125
}
2112
2126
}
2113
2127
2128
+ if (exception instanceof FirebaseAuthUserCollisionException ) {
2129
+ error .putString ("email" , ((FirebaseAuthUserCollisionException ) exception ).getEmail ());
2130
+ }
2131
+
2114
2132
if (exception instanceof FirebaseAuthMultiFactorException ) {
2115
2133
final FirebaseAuthMultiFactorException multiFactorException =
2116
2134
(FirebaseAuthMultiFactorException ) exception ;
0 commit comments