Search code examples
androidfirebasekotlingoogle-cloud-firestorefirebase-authentication

How to login using phone number via FirebaseAuth without OTP?


So I am building an app and the owner asked me to create a backdoor that allows him to sign in to a phone number without using OTP.

How to do that using FirebaseAuth in Kotlin?

Thanks.


Solution

  • As far as I understand you need a way in which the owner can access your app without actually authenticating. This is not much about code as it's about logic. So the best option I can think of would be to check the phone number of the owner inside your application code. This number should be stored inside a database like Firestore or the Realtime Database. This means that each time the user enters the phone number, you need to check against the phone number of the owner. If the number that is introduced belongs to the owner, then navigate to the desired screen, otherwise go ahead with the authentication flow. There are however two more things to mention:

    1. If the number of your owner is known by many people, then insted of the phone number you can choose a highly unpredictable number, so no one can guess it.
    2. Enforce that number inside your Firestore Security Rules or Realtime Database Security Rules.