private boolean authenticateUser(final String role, final String userId) {
DatabaseReference roleReference = FirebaseDatabase.getInstance().getReference().child("role").child(role);
roleReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
HashMap<String, String> map = (HashMap<String, String>) dataSnapshot.getValue();
if (map != null) {
Set<String> userIds = map.keySet();
if (userIds.contains(userId))
authenticationResult = true;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return authenticationResult;
}
Above is a function to authenticate user. I want to return true if (userIds.contains(userId))
else false. But the authenticateUser always returns false.