Firebase phone auth check if reCAPTCHA flow was triggered

Viewed 179

From the docs

The reCAPTCHA flow will only be triggered when SafetyNet is unavailable or your device does not pass suspicion checks. Nonetheless, you should ensure that both scenarios are working correctly.

I want to check if the user was shown the reCAPTCHA screen so I could track it in the app analytics.

I couldn't find any way of achieving this in the docs. Is there something I missed, or is this not available for now?

1 Answers
  1. Keep a flag that will be toggled on navigating away from the current Activity or Fragment. Maybe you need to take care of the case when the user minimized the app (pressing the home, or call), otherwise you'll get inaccurate analytics.
 val authCompleted = AtomicBoolean(false)
  1. Toggle it when you explicitly need to navigate to next screen,
     override fun onAuthCompleted(){
         if(authCompleted.compareAndSet(false, true)){
             findNavController().navigate(nextDirection)
         }
     }
  1. If you navigate away without this flag being flipped, means you are either navigating to show reCAPTCHA ActivityDialog
    override fun onStop(){
       super.onStop()
       if(!isFinishing && !authCompleted.get()){
         //you are probably given the reCAPTCHA dialog
       }
    }
Related