I built with Firebase two options for registration, one can register as an employer and another option to register as an worker. I gave an ID to them, and each employer received the letter 'e' at the beginning of the ID and the worker received the letter 'w' at the beginning of the ID so that I could identify them.
I also created the possibility of connecting with Firebase and I want if I connect as a worker I will switch to a certain screen and if I connect as an employer I will switch to another screen.
I store the information inside the Firestore. Each document in the collection receives the UID of that user within the document. The ID is found with the letters.
I try this.
private char s = 'e';
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
mDatabase.collection("employer").document(mUser.getUid()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful())
{
DocumentSnapshot documentSnapshot = task.getResult();
index = documentSnapshot.getString("ID");
ID = index.charAt(0);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mDatabase.collection("worker").document(mUser.getUid()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
DocumentSnapshot documentSnapshot = task.getResult();
index = documentSnapshot.getString("ID");
ID = index.charAt(0);
}
});
}
});
if(mUser.isEmailVerified())
{
if(ID == s)
{
Intent k = new Intent(login_page.this,home_screen_employer.class);
startActivity(k);
}
else {
Intent k = new Intent(login_page.this,home_screen_worker.class);
startActivity(k);
}
}