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 ;
@@ -868,9 +869,12 @@ private void signInWithCredential(
868
869
@ ReactMethod
869
870
public void signInWithProvider (String appName , String providerId , @ Nullable String email , Promise promise ){
870
871
OAuthProvider .Builder provider = OAuthProvider .newBuilder (providerId );
872
+
871
873
if (email != null ){
872
874
provider .addCustomParameter ("login_hint" , email );
873
875
}
876
+ provider .addCustomParameter ("prompt" , "select_account" );
877
+
874
878
Activity activity = getCurrentActivity ();
875
879
FirebaseApp firebaseApp = FirebaseApp .getInstance (appName );
876
880
FirebaseAuth firebaseAuth = FirebaseAuth .getInstance (firebaseApp );
@@ -908,9 +912,12 @@ public void onFailure(@NonNull Exception e) {
908
912
@ ReactMethod
909
913
public void linkWithProvider (String appName , String providerId , @ Nullable String email , Promise promise ){
910
914
OAuthProvider .Builder provider = OAuthProvider .newBuilder (providerId );
915
+
911
916
if (email != null ){
912
917
provider .addCustomParameter ("login_hint" , email );
913
918
}
919
+ provider .addCustomParameter ("prompt" , "select_account" );
920
+
914
921
Activity activity = getCurrentActivity ();
915
922
FirebaseApp firebaseApp = FirebaseApp .getInstance (appName );
916
923
FirebaseAuth firebaseAuth = FirebaseAuth .getInstance (firebaseApp );
@@ -1977,7 +1984,7 @@ private void promiseWithAuthResult(AuthResult authResult, Promise promise) {
1977
1984
if (authResult .getCredential () instanceof OAuthCredential ){
1978
1985
OAuthCredential creds = (OAuthCredential ) authResult .getCredential ();
1979
1986
WritableMap credentialMap = Arguments .createMap ();
1980
-
1987
+
1981
1988
credentialMap .putString ("providerId" , creds .getProvider ());
1982
1989
credentialMap .putString ("signInMethod" , creds .getSignInMethod ());
1983
1990
@@ -2037,15 +2044,23 @@ private void promiseWithAuthResult(AuthResult authResult, Promise promise) {
2037
2044
*/
2038
2045
private void promiseRejectAuthException (Promise promise , Exception exception ) {
2039
2046
WritableMap error = getJSError (exception );
2040
-
2047
+
2041
2048
final String sessionId = error .getString ("sessionId" );
2042
2049
final MultiFactorResolver multiFactorResolver = mCachedResolvers .get (sessionId );
2043
2050
WritableMap resolverAsMap = Arguments .createMap ();
2051
+
2052
+ WritableMap map = Arguments .createMap ();
2044
2053
if (multiFactorResolver != null ) {
2045
2054
resolverAsMap = resolverToMap (sessionId , multiFactorResolver );
2055
+ map .putMap ("resolver" , resolverAsMap );
2046
2056
}
2047
- rejectPromiseWithCodeAndMessage (
2048
- promise , error .getString ("code" ), error .getString ("message" ), resolverAsMap );
2057
+
2058
+ if (error .getString ("email" ) != null ){
2059
+ map .putString ("email" , error .getString ("email" ));
2060
+ }
2061
+
2062
+ rejectPromiseWithMap (
2063
+ promise , error .getString ("code" ), error .getString ("message" ), map );
2049
2064
}
2050
2065
2051
2066
/**
@@ -2060,7 +2075,6 @@ private WritableMap getJSError(Exception exception) {
2060
2075
String invalidEmail = "The email address is badly formatted." ;
2061
2076
2062
2077
System .out .print (exception );
2063
-
2064
2078
try {
2065
2079
FirebaseAuthException authException = (FirebaseAuthException ) exception ;
2066
2080
code = authException .getErrorCode ();
@@ -2096,7 +2110,7 @@ private WritableMap getJSError(Exception exception) {
2096
2110
+ " before retrying this request." ;
2097
2111
break ;
2098
2112
case "ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL" :
2099
- message =
2113
+ message =
2100
2114
"An account already exists with the same email address but different sign-in"
2101
2115
+ " credentials. Sign in using a provider associated with this email address." ;
2102
2116
break ;
@@ -2134,6 +2148,10 @@ private WritableMap getJSError(Exception exception) {
2134
2148
}
2135
2149
}
2136
2150
2151
+ if (exception instanceof FirebaseAuthUserCollisionException ) {
2152
+ error .putString ("email" , ((FirebaseAuthUserCollisionException ) exception ).getEmail ());
2153
+ }
2154
+
2137
2155
if (exception instanceof FirebaseAuthMultiFactorException ) {
2138
2156
final FirebaseAuthMultiFactorException multiFactorException =
2139
2157
(FirebaseAuthMultiFactorException ) exception ;
0 commit comments