firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.27k stars 574 forks source link

FirebaseAuth crash on captcha link when no browser is installed #4006

Open adiliqbl opened 2 years ago

adiliqbl commented 2 years ago

Hi, we're using Firebase Auth's phone number method for users to signin. We've seen crashes when user doesn't have a browser installed & firebase tries opens captcha link. Crash is always a bad experience for users & since I believe there's nothing we can do here, maybe it would be nice to have exception thrown instead of causing a crash.

Steps to reproduce:

Observed Results:

Expected Results:

sahilpocketfm commented 2 years ago

any update on the fix?

thatfiredev commented 2 years ago

Thank you for the detailed explanation. I was able to reproduce this issue and it seems like it's a bug in Firebase Auth and not in FirebaseUI specifically. I'm transferring this issue to the appropriate repository.

google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

thatfiredev commented 2 years ago

While the Auth team investigates this further, there's a current workaround to prevent your app from crashing. You can create a function to check if a browser is available on the device:

private fun isBrowserAvailable(): Boolean {
    val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://"))
    val info = browserIntent.resolveActivity(requireContext().packageManager)
    return info != null
}

And call it right before calling PhoneAuthProvider.verifyPhoneNumber():

if (isBrowserAvailable()) {
    // Browser is available. Continue with verification
    PhoneAuthProvider.verifyPhoneNumber(options)
} else {
    // No browser found. Notify the user
    Toast.makeText(context, "No browser found to handle verification",
        Toast.LENGTH_SHORT).show()
}

If your app targets API Level 30 (Android 11), you'll also need to add a <queries> entry to your manifest due to the newly introduced package visibility restrictions:

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
        </intent>
    </queries>

Since this issue was originally opened on the FirebaseUI-Android repo, I'll be sure to update that library to handle these cases.