FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)
.addOnCompleteListener(getActivity(), task -> {
if (task.isSuccessful()) {
// here you get the logged-in user UID if login successful
String userUID = FirebaseAuth.getInstance().getCurrentUser().getUid()
// set the path of your database and get the UID from it
String path = FirebaseDatabase.getInstance().getReference("yourRootKey").child("User").child(userUID).child("Email")
//add a listener to get value
path.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// here you can get value from dataSnapshot as above you can achieve from onDataChange and check the type
// and navigate to user
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("onCancelled", databaseError.toException());
}
});
} else {
// login failed display as toast
}
});
1条答案
按热度按时间c0vxltue1#
很简单,你可以这样得到这个uid