Firebase Phone Auth with Clean Architecture

Viewed 226

I am trying to implement Firebase Phone Auth in my project which is based on a clean architecture. I am confused about PhoneAuthOptions class, builder of which requires activity on one hand (which belongs to presentation layer) and on the other hand, auth (which belongs to data layer). How can I provide this builder with activity and auth at the same time without violating principles of code decoupling in Clean Architecture?

val options = PhoneAuthOptions.newBuilder(auth)
    .setPhoneNumber(phoneNumber)       // Phone number to verify
    .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
    .setActivity(this)                 // Activity (for callback binding)
    .setCallbacks(callbacks)          // OnVerificationStateChangedCallbacks
    .build()
PhoneAuthProvider.verifyPhoneNumber(options)
1 Answers

To be honest I think that the Android understanding is a bit messed up. If you see Uncle's Bob picture:

https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

The DB and the UI are in the same layer. That is what makes the app clean - these stuff are implementation details. The inner layers do not care if you are using Room or other SQL library, OKHttp or HttpUrlConnection. Such libraries are hidden behind interfaces. The Clean Architecture sits on top of "Inversion of Control".

https://en.wikipedia.org/wiki/Inversion_of_control

Basically, the inner layers are pure Java/Kotlin modules. They have interfaces declared in the same modules on which they depend. And outer layers implement the interfaces.

I think that this top to bottom(from the Google docs) is more easily understandable on a first glance, but it harms the understanding of what Uncle Bob wanted to achieve.

I would advise you to check this approach where in the end you have 2 modules: https://www.raywenderlich.com/3595916-clean-architecture-tutorial-for-android-getting-started

Check how it looks:

https://koenig-media.raywenderlich.com/uploads/2019/06/architecture-overview-650x343.png

Also, think about it - Presentation layer is when you need to present something. Do you have a Presentation layer in a backed application? Do you have an UI there? But can it be clean or not? Yes, it can. So what you care to put in the same place is "The Android stuff". They are your implementation detail.

So when you look at it from that point of view - Activity and PhoneAuthOptions will perfectly get along and you still will be clean. :)

Related