Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can firebase phone auth be implemented in view model?

I'm trying to add the Firebase Phone Authentication code inside a View Model using Kotlin. The problem is that the PhoneAuthProvider requires an activity. Does anyone know how can this code be implemented inside a View Model without the need of an activity?

Thanks!

val mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks ...

val options = PhoneAuthOptions.newBuilder(auth).apply {
  setPhoneNumber(phoneNumber)
  setTimeout(120L, TimeUnit.SECONDS)
  setActivity(this) <-------------------------- // Activity (for callback binding)
  setCallbacks(mCallbacks)
}.build()
PhoneAuthProvider.verifyPhoneNumber(options)
like image 225
Toufic Batache Avatar asked Oct 28 '25 03:10

Toufic Batache


1 Answers

It turned out to be an intentional change in API 20 (check out this issue on Github), even though it violates the MVVM architecture. The reason an activity is needed is that the method falls back to reCAPTCHA. The right way to achieve it is "yet to be determined".

like image 197
Toufic Batache Avatar answered Oct 30 '25 23:10

Toufic Batache