Simple login Firebase

Asked

Viewed 100 times

3

I already have a main login with Firebase auth. But I need to implement another login within that system, because the client can add other administrators. The login will be simple even, just check if the password and email check.

I have this method that logs in:

public void retrive(String uid, String senha) {
    raiz
            .child(CHILD) // ex: adms
            .child(uid) // ex: rafael@email
            .equalTo(senha,"senha")
            .addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.getValue() != null) {
                        // ok
                    }else {
                        // false
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    //false
                }
            });
}

My Firebase Json looks like this: Adm father and children:

{
    "rafael@gmailcom": {
        "ativo": true,
        "codigo": "rafael@gmailcom",
        "dataNascimento": 944515274,
        "email": "[email protected]",
        "nome": "Rafael Aparecido da silva",
        "privilegios": {
            "ACESSO_FINANCEIRO": true,
            "AGENDAR_CONSULTA": false,
            "CADASTRO_PACIENTE ": false,
            "CADASTRO_PACIENTE_": false,
            "MANTER_ADM": false,
            "RECEBER_PAGAMENTO": true
        },
        "senha": "teste"
    }
}

I can’t get it to bring the desired user.

1 answer

1

Firebase does not allow you to perform a 2-condition Query. Which means you will need to log in in 2 steps:

1.Search for the user with this ID

2.Check that the password is correct:

public void retrive(String uid, String senha) {
    raiz.child(CHILD) // ex: adms
        .child(uid) // ex: rafael@email
        .addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.child("senha").getValue() == Senha) {
                        // ok
                    }else {
                        // false
                    }
            }
            @Override
            public void onCancelled(DatabaseError databaseError) {
                //false
            }
        });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.