Validating whether or not there is a user with Firebase

0

I created a web registration, in Firebase. I can register, but if I soon with a valid email and password, I am not redirected into the system. And if I put an email and any password, it does not show the phrase "Invalid user or password" that I programmed to be displayed

HTML:

<div class="container-fluid">
<div class="row">
    <div class="col-md-4"></div>
    <div class="col-md-4">
        <form class="form-signin formularioLogin">

            <h3 align="center">Domanda</h3>

            <label>E-mail do Estabelecimento</label>
            <div>
                <input class="form-control" type="email" name="email" ng-model="admin.email"
                placeholder="[email protected]">
            </div>

            <label>Senha</label>
            <div>
                <input class="form-control adminSenha" type="password" ng-model="admin.senha">
            </div>

            <button class="btn btn-block btn-success btnLogar" ng-click="logar(admin)">Entrar</button>
            <div>{{ loginErro }}</div>

            <button class="btn btn-block btn-primary btnLogar" ng-click="cadastrar(admin)">Cadastrar</button>

        </form>
    </div>
    <div class="col-md-4"></div>
</div>

Controller:

$scope.logar = function(admin){

    var email = admin.email;
    var password = admin.senha;

    firebase.auth().signInWithEmailAndPassword(email, password)
    .then( function ( result ) {
        //Usuário autenticado com sucesso
        //Seu código para redirecionar vem aqui.
        console.log(result);
        $location.path('/inicial');
    }, function ( error ) {
        //Ops, ocorreu um erro, pode deixar seu código tratando o erro aqui
        console.log('erro: '+error);
        $location.path('/');
    })


}
    
asked by anonymous 19.07.2017 / 19:50

1 answer

0

You are only dealing with the error scenario, with catch ...

As a promise you should also treat what to do if it works out right on the "then".

Ex:

firebase.auth().signInWithEmailAndPassword(email, password)
.then( function ( result ) {
    //Usuário autenticado com sucesso
    //Seu código para redirecionar vem aqui.
}, function ( error ) {
    //Ops, ocorreu um erro, pode deixar seu código tratando o erro aqui
})
    
19.07.2017 / 20:26