FirebaseAuth with Angular: User Login

I use Angular (1.3.5) and Firebase to write a toy blog program, and I'm currently struggling with the login part.

First I created an Angular module:

var blogApp = angular.module('blogApp', ['ngRoute', 'firebase', 'RegistrationController']);

Then on top of blogApp, I created a controller called ** RegistrationController **:

blogApp.controller('RegistrationController', function ($scope, $firebaseAuth, $location) {

        var ref = new Firebase('https://myAppName.firebaseio.com');
       // var authLogin = $firebaseAuth(ref);


        $scope.login = function(){

            ref.authWithPassword({
                email: $scope.user.email,
                password: $scope.user.password
            }, function(err, authData) {
                if (err) {
                    $scope.message = 'login error';
                } else {
                    $scope.message = 'login sucessful!';
                }
            });
        }; // login

  });  //RegistrationController

I attached the method login()to ng-submit in my user login form in the scope RegistratinController.

When I click to submit the login form, the form does not make any response, without any errors.

The login form only works when I double-click the "Submit" button - why? confusing

+4
source share
2 answers

JavaScript Firebase, AngularFire .

Firebase $firebaseAuth.

var auth = $firebaseAuth(ref);

auth.$authWithPassword.

    $scope.login = function(){

        auth.$authWithPassword({
            email: $scope.user.email,
            password: $scope.user.password
        }, function(err, authData) {
            if (err) {
                $scope.message = 'login error';
            } else {
                $scope.message = 'login successful!';
            }
        });
    }; // login

AngularFire - Angular Firebase, . AngularFire $scope.apply .

, . $timeout, $firebaseAuth.

+4

jacobawenger, , :

AngularFire 0.9.0?

:

myApp.controller('RegistrationController', 
    function($scope, $firebaseAuth, $location) {

    var ref = new Firebase('https://myApp.firebaseio.com');
    var simpleLogin = $firebaseAuth(ref);

    $scope.login = function() {
        simpleLogin.$authWithPassword({
            email: $scope.user.email,
            password: $scope.user.password
        }).then(function() {
            $location.path('/mypage');
        }, function(err) {
            $scope.message = err.toString();
        });
    } // login

}); // RegistrationController
+1

All Articles