0

So, I am trying to make an android app which has both Login and Register Activities, I have configured the RegisterActivity to store the data into the firebase realtime database in the following way :

enter image description here

and I am using Firebase PhoneAuth to register the user. The problem comes when I am designing the LoginActivity, in which after the user enters the mobile number, I somehow have to check whether if he/she is already registered or not, if registered log him/her in IF not then I forward him/her to the RegisterActivity. I was unable to find a way to do it.

Is there any way I can detect whether a phone number is already registered or not?

Satyam Bansal
  • 363
  • 1
  • 4
  • 11

1 Answers1

0

Declare this in your Login Activity:

@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    if(currentUser!=null){
        startActivity(new Intent(getApplicationContext(),Activity.class)); //Choose the activity you want to load in Activity.class, for eg, MainAcitivity.class
        finish();}
    else{
        startActivity(new Intent(getApplicationContext(),RegisterActivity.class));
        finish();}

}
  • But this will return 'null' only if the user is not currently signed on the this instance, but what if the user is already registered in the auth thing but has signed out – Satyam Bansal Nov 29 '20 at 09:38
  • If the user has already registered and signed out, then he will login again, that's how it works. However, if the user has just exited the application, the above code will prevent him from going through the login process again. – Mokshda Gangrade Nov 29 '20 at 09:57
  • But what if a user hasn't previously registered and he/she tries to Login through the LoginActivity and since no record of the user exists earlier I want to redirect them to the RegisterActivity – Satyam Bansal Nov 29 '20 at 10:08