Firebase - How to check whether a user has already signed up using Phone Number

后端 未结 7 1489
梦毁少年i
梦毁少年i 2021-01-04 02:57

I am using firebase phone Authentication . When a user creates a account using phone number and next time he creates account with same phone number Than I want to show a m

7条回答
  •  走了就别回头了
    2021-01-04 03:30

    I have done this into my project and it is working perfectly, you can use this, you can use your phone number instead of "deviceId".

     mFirebaseDatabaseRefrence.orderByChild("deviceId").equalTo(deviceId).addListenerForSingleValueEvent(new ValueEventListener() {
    
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.getValue() != null) {
                        Log.d(TAG, "Datasnap Shots: " + dataSnapshot.getValue());
                          /* if alredy exist and check for first time, second time isExist=true*/
                        if (!isExist) {
    
                            for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
                                UserbasicInfo user = userSnapshot.getValue(UserbasicInfo.class);
                                  Toast.makeText(UserInfoActivity.this, "User already exist...!", Toast.LENGTH_SHORT).show();
    
                            }
    
                        }
                        isExist = true;
                    } else {
                        isExist = false;
                    }
                }
    
                @Override
                public void onCancelled(DatabaseError databaseError) {
    
                }
            });
    
            /*if not exist add data to firebase*/
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    Log.d(TAG, "isExist: " + isExist);
                    if (!isExist) {
                        addDataToDB(false);
                    } else {
                        addDataToDB(true);
    
                    }
                }
            };
            new Handler().postDelayed(runnable, 5000);
    

提交回复
热议问题