I am trying to get the user UID from the Firebase auth, but it's giving me a null value. I have one admin which will register many schools and each school will have its own id by push key. The admin will regsiter schools as he wants and they can only login after they register them.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
MngEmail = (EditText)findViewById(R.id.MngEmailField);
MngPassword = (EditText)findViewById(R.id.mngPass);
MngFrgtPass = (TextView)findViewById(R.id.MngForText);
MngLoginBtn = (Button)findViewById(R.id.MngBtn);
loadingbar = new ProgressDialog(this);
MngAuth = FirebaseAuth.getInstance();
SuperAdminUId = MngAuth.getCurrentUser().getUid();
String key = MngRef.child("SchoolData").child(SuperAdminUId).getKey();
MngRef = FirebaseDatabase.getInstance().getReference().child("SchoolData").child(SuperAdminUId).child(key);
MngFrgtPass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TO Dooo
}
});
MngLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Query query = MngRef.orderByChild("SchoolEmail").equalTo(MngEmail.getText().toString().trim());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
// dataSnapshot is the "issue" node with all children with id 0
for (DataSnapshot user : dataSnapshot.getChildren()) {
// do something with the individual "issues"
School schoolinfo = user.getValue(School.class);
if (schoolinfo.equals(MngPassword.getText().toString().trim())) {
sendMngToMain();
} else {
Toast.makeText(login.this, "Password is wrong", Toast.LENGTH_LONG).show();
}
}
} else {
Toast.makeText(login.this, "User not found", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}