4646import com .google .firebase .auth .FirebaseAuth ;
4747import com .google .firebase .auth .FirebaseAuthException ;
4848import com .google .firebase .auth .FirebaseAuthInvalidCredentialsException ;
49+ import com .google .firebase .auth .FirebaseAuthUserCollisionException ;
4950import com .google .firebase .auth .FirebaseAuthMultiFactorException ;
5051import com .google .firebase .auth .FirebaseAuthProvider ;
5152import com .google .firebase .auth .FirebaseAuthSettings ;
@@ -845,9 +846,12 @@ private void signInWithCredential(
845846 @ ReactMethod
846847 public void signInWithProvider (String appName , String providerId , @ Nullable String email , Promise promise ){
847848 OAuthProvider .Builder provider = OAuthProvider .newBuilder (providerId );
849+
848850 if (email != null ){
849851 provider .addCustomParameter ("login_hint" , email );
850852 }
853+ provider .addCustomParameter ("prompt" , "select_account" );
854+
851855 Activity activity = getCurrentActivity ();
852856 FirebaseApp firebaseApp = FirebaseApp .getInstance (appName );
853857 FirebaseAuth firebaseAuth = FirebaseAuth .getInstance (firebaseApp );
@@ -885,9 +889,12 @@ public void onFailure(@NonNull Exception e) {
885889 @ ReactMethod
886890 public void linkWithProvider (String appName , String providerId , @ Nullable String email , Promise promise ){
887891 OAuthProvider .Builder provider = OAuthProvider .newBuilder (providerId );
892+
888893 if (email != null ){
889894 provider .addCustomParameter ("login_hint" , email );
890895 }
896+ provider .addCustomParameter ("prompt" , "select_account" );
897+
891898 Activity activity = getCurrentActivity ();
892899 FirebaseApp firebaseApp = FirebaseApp .getInstance (appName );
893900 FirebaseAuth firebaseAuth = FirebaseAuth .getInstance (firebaseApp );
@@ -1954,7 +1961,7 @@ private void promiseWithAuthResult(AuthResult authResult, Promise promise) {
19541961 if (authResult .getCredential () instanceof OAuthCredential ){
19551962 OAuthCredential creds = (OAuthCredential ) authResult .getCredential ();
19561963 WritableMap credentialMap = Arguments .createMap ();
1957-
1964+
19581965 credentialMap .putString ("providerId" , creds .getProvider ());
19591966 credentialMap .putString ("signInMethod" , creds .getSignInMethod ());
19601967
@@ -2014,15 +2021,23 @@ private void promiseWithAuthResult(AuthResult authResult, Promise promise) {
20142021 */
20152022 private void promiseRejectAuthException (Promise promise , Exception exception ) {
20162023 WritableMap error = getJSError (exception );
2017-
2024+
20182025 final String sessionId = error .getString ("sessionId" );
20192026 final MultiFactorResolver multiFactorResolver = mCachedResolvers .get (sessionId );
20202027 WritableMap resolverAsMap = Arguments .createMap ();
2028+
2029+ WritableMap map = Arguments .createMap ();
20212030 if (multiFactorResolver != null ) {
20222031 resolverAsMap = resolverToMap (sessionId , multiFactorResolver );
2032+ map .putMap ("resolver" , resolverAsMap );
20232033 }
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 );
20262041 }
20272042
20282043 /**
@@ -2037,7 +2052,6 @@ private WritableMap getJSError(Exception exception) {
20372052 String invalidEmail = "The email address is badly formatted." ;
20382053
20392054 System .out .print (exception );
2040-
20412055 try {
20422056 FirebaseAuthException authException = (FirebaseAuthException ) exception ;
20432057 code = authException .getErrorCode ();
@@ -2073,7 +2087,7 @@ private WritableMap getJSError(Exception exception) {
20732087 + " before retrying this request." ;
20742088 break ;
20752089 case "ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL" :
2076- message =
2090+ message =
20772091 "An account already exists with the same email address but different sign-in"
20782092 + " credentials. Sign in using a provider associated with this email address." ;
20792093 break ;
@@ -2111,6 +2125,10 @@ private WritableMap getJSError(Exception exception) {
21112125 }
21122126 }
21132127
2128+ if (exception instanceof FirebaseAuthUserCollisionException ) {
2129+ error .putString ("email" , ((FirebaseAuthUserCollisionException ) exception ).getEmail ());
2130+ }
2131+
21142132 if (exception instanceof FirebaseAuthMultiFactorException ) {
21152133 final FirebaseAuthMultiFactorException multiFactorException =
21162134 (FirebaseAuthMultiFactorException ) exception ;
0 commit comments