firebase-android-sdk
firebase-android-sdk copied to clipboard
Remove dependency on Activity for Firebase Authentication
What feature would you like to see?
Describe the feature you would like to add, ideally proposing a specific API.
After the latest release https://firebase.google.com/support/release-notes/android#auth_v20-0-0 in order to do PhoneAuthProvider.verifyPhoneNumber
we need to pass an instance of Activity
.
In our codebase we used to use old implementation with executor and it was handled in data layer that does not have an access to the UI layer, and then it is transformed to kotlin flow.
With required Activity
it is no longer possible and we will have to violate ViewModel patterns and pass activity through viewModel. AFAIU Activity is required to remove callbacks, my proposal is to add removeVerifyPhoneNumberCallback
so we can explicitly remove it without providing instance of activity to the library.
How would you use it?
We transform verifyPhoneNumber
to kotlin flow in data layer that does not have an access to UI since we don't want to violate viewModel patterns, with the new implementation of Firebase auth we have to either violate rules and pass instance of activity through viewModel or we have to do verifyPhone stuff in Fragment or Activity. Both options feel wrong in terms of code quality and testabilty
Tell us how you'd use this feature in your app.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
This should be done ASAP. It's a direct violation of the Android MVVM architecture. How are developers supposed to add this piece of code inside of their ViewModel
with a reference to an Activity
?
val options = PhoneAuthOptions.newBuilder(auth).apply {
setPhoneNumber(phoneNumber)
setTimeout(120L, TimeUnit.SECONDS)
setActivity(this) <--------------------------------- Activity (for callback binding)
setCallbacks(mCallbacks)
}.build()
PhoneAuthProvider.verifyPhoneNumber(options)
@rlazo Please change the label here, this is not a feature request, this is a bug that needs to be fixed.
Thanks for the code - we're tracking this internally at b/177077823
Hey @touficbatache , this is an intentional change as part of the 19.->20. breaking changes, so marking it as a feature request is appropriate for now. We're considering adding a method that doesn't fall back to reCAPTCHA (which is why we require an Activity), but we haven't yet determined the right way to do that.
Hello @malcolmdeck, I still believe it's a bug, since it violates android's MVVM architecture. One way you could do it is adding a callback to the listeners and letting the developers implement the reCAPTCHA on their own. What do you think? The way it's built now is really bad...
Your guys had progress on it? I've implemented an RX layer on top of the method verifyPhoneNumber
and the problem discussed here is stucking my app... It's so annoying... How could GOOGLE developers unconsider the MVVM and RX pattern when developing the sdk?
What is the alternate pattern?
@malcolmdeck It's been more then a year now any updates?
@malcolmdeck It's been more then a year now any updates?
Still the same issue and I can't understand how it's not changed yet.
heey guys, any updates?
Are we still waiting for an update?
Hi @InakiBes, this change was released earlier this year. Please check release notes here https://firebase.google.com/support/release-notes/android#2023-03-28