Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebaseUI-auth is not returning a result after a blocking function throws an HTTP 400 error. #2175

Open
Aburaya5123 opened this issue Dec 2, 2024 · 0 comments

Comments

@Aburaya5123
Copy link

Step 1: Are you in the right place?

For issues or feature requests related to the code in this repository file a GitHub issue.

Step 2: Describe your environment

  • Android device: OPPO Reno5A
  • Android OS version: Android12
  • Google Play Services version: 22.1.2
  • Firebase/Play Services SDK version: 33.6.0
  • FirebaseUI version: 8.0.2

Step 3: Describe the problem:

I'm facing an issue with FirebaseUI auth using Google accounts.
I've set up a blocking function in Firebase functions to control which email addresses can sign up.

@identity_fn.before_user_created()
def email_filtering(
        event: identity_fn.AuthBlockingEvent) -> identity_fn.BeforeCreateResponse | None:
    user = event.data

    if user.email is None or not "@example.com" in user.email:
        raise https_fn.HttpsError(code=https_fn.FunctionsErrorCode.INVALID_ARGUMENT,
                                  message="Unauthorized email")

The problem is when the function returns a 400 error, FirebaseAuthUIAuthenticationResult callback isn't being invoked in Android.

    private val signIn: ActivityResultLauncher<Intent> =
            registerForActivityResult(FirebaseAuthUIActivityResultContract(), this::onSignInResult)

    override fun onStart() {
        super.onStart()
        if (Firebase.auth.currentUser == null) {
            val signInIntent = AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setTheme(R.style.LoginTheme)
                .setAvailableProviders(listOf(
                    AuthUI.IdpConfig.GoogleBuilder().build(),
                ))
                .build()
            signIn.launch(signInIntent)
        } else {
            goToMainActivity()
        }
    }

    private fun onSignInResult(result: FirebaseAuthUIAuthenticationResult) {
        if (result.resultCode == RESULT_OK) {
            Log.d(TAG, "onSignInResult(): Sign in succeed")
        } else {
            val response = result.idpResponse
            if (response == null) {
                Log.w(TAG, "onSignInResult(): Sign in canceled")
            } else {
                Log.w(TAG, "onSignInResult(): Sign in error", response.error)
            }
        }
        goToMainActivity()
    }

If the email is correct one, the sign-up process completes successfully.
Otherwise the function returns 400 error as intended, but FirebaseUI doesn't appear to be handling it appropriately.
Can you help me understand why this is happening and how to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant