Skip to content

Commit de7519b

Browse files
felipe-gouveiasamtstern
authored andcommitted
Added verification for fail to sign in when account is disabled by th… (firebase#1632)
1 parent 58b8b11 commit de7519b

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ private void handleSignInResponse(int resultCode, @Nullable Intent data) {
351351
startActivity(intent);
352352
}
353353

354+
if (response.getError().getErrorCode() == ErrorCodes.ERROR_USER_DISABLED) {
355+
showSnackbar(R.string.account_disabled);
356+
return;
357+
}
358+
354359
showSnackbar(R.string.unknown_error);
355360
Log.e(TAG, "Sign-in error: ", response.getError());
356361
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878

7979
<string name="sign_in_cancelled">Sign in cancelled</string>
8080
<string name="no_internet_connection">No internet connection</string>
81+
<string name="account_disabled">Account is disabled by the administrator</string>
8182
<string name="unknown_error">An unknown error occurred</string>
8283

8384
<string name="title_anonymous_upgrade">FirebaseUI Anonymous Account Linking</string>

auth/src/main/java/com/firebase/ui/auth/ErrorCodes.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public final class ErrorCodes {
6666
*/
6767
public static final int EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR = 11;
6868

69+
/**
70+
* Attempting to auth with account that is currently disabled in the Firebase console.
71+
*/
72+
public static final int ERROR_USER_DISABLED = 12;
73+
6974
private ErrorCodes() {
7075
throw new AssertionError("No instance for you!");
7176
}
@@ -100,6 +105,8 @@ public static String toFriendlyMessage(@Code int code) {
100105
case EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR:
101106
return "The session associated with this sign-in request has either expired or " +
102107
"was cleared";
108+
case ERROR_USER_DISABLED:
109+
return "The user account has been disabled by an administrator.";
103110
default:
104111
throw new IllegalArgumentException("Unknown code: " + code);
105112
}
@@ -120,7 +127,8 @@ public static String toFriendlyMessage(@Code int code) {
120127
EMAIL_LINK_WRONG_DEVICE_ERROR,
121128
EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR,
122129
EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR,
123-
EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR
130+
EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR,
131+
ERROR_USER_DISABLED
124132
})
125133
@Retention(RetentionPolicy.SOURCE)
126134
public @interface Code {

auth/src/main/java/com/firebase/ui/auth/viewmodel/idp/SocialProviderResponseHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.firebase.auth.AuthCredential;
2828
import com.google.firebase.auth.AuthResult;
2929
import com.google.firebase.auth.EmailAuthProvider;
30+
import com.google.firebase.auth.FirebaseAuthInvalidUserException;
3031
import com.google.firebase.auth.FirebaseAuthUserCollisionException;
3132

3233
import java.util.List;
@@ -108,6 +109,16 @@ public void onFailure(@NonNull Exception e) {
108109
e));
109110
}
110111
});
112+
} else if (e instanceof FirebaseAuthInvalidUserException){
113+
setResult(Resource.<IdpResponse>forFailure(
114+
new FirebaseUiException(
115+
ErrorCodes.ERROR_USER_DISABLED,
116+
ErrorCodes.toFriendlyMessage(
117+
ErrorCodes.ERROR_USER_DISABLED
118+
)
119+
)
120+
));
121+
return;
111122
}
112123
}
113124
});

0 commit comments

Comments
 (0)