firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

Remove dependency on Activity for Firebase Authentication

Open ReginFell opened this issue 3 years ago • 10 comments

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.

ReginFell avatar Dec 08 '20 12:12 ReginFell

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

google-oss-bot avatar Dec 08 '20 12:12 google-oss-bot

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.

touficbatache avatar Jan 04 '21 11:01 touficbatache

Thanks for the code - we're tracking this internally at b/177077823

strom2357 avatar Jan 08 '21 19:01 strom2357

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.

malcolmdeck avatar Jan 11 '21 18:01 malcolmdeck

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...

touficbatache avatar Jan 11 '21 19:01 touficbatache

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?

reberthkss avatar Mar 03 '22 01:03 reberthkss

What is the alternate pattern?

hexdecimal16 avatar Apr 19 '22 12:04 hexdecimal16

@malcolmdeck It's been more then a year now any updates?

hexdecimal16 avatar Apr 19 '22 12:04 hexdecimal16

@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.

hompiler avatar May 14 '22 01:05 hompiler

heey guys, any updates?

Temirlannn avatar Aug 08 '22 10:08 Temirlannn

Are we still waiting for an update?

InakiBes avatar Dec 04 '23 13:12 InakiBes

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

bhparijat avatar Dec 19 '23 06:12 bhparijat