1

이전에이 문제에 대한 게시물을 보았지만 구식이거나 솔루션과 비슷합니다.

기본적으로 내 컨트롤러에는 authCtrl.login 및 authCtrl.register의 두 가지 기능이 있습니다. Auth. $ createUserWithEmailAndPassword()에 대한 등록기 호출은 정상적으로 작동하지만 Auth. $ authWithPassword()에 대한 로그인 호출은 "..is not a function"오류가 발생하므로 않습니다. 내 인생에서 여기서 잘못된 점을 찾아 낼 수 없습니까?

auth.service.js :

angular.module('angularfireSlackApp') 
.factory('Auth', function($firebaseAuth, $firebaseObject){ 
var auth = $firebaseAuth(); 

return auth; 
}); 

auth.controller.js : 여기

내 설정이다

angular.module('angularfireSlackApp') 
.controller('AuthCtrl', function(Auth, $state){ 
var authCtrl = this; 

authCtrl.user = { 
    email: '', 
    password: '' 
}; 

authCtrl.login = function() { 
// Why is this not a function 
Auth.$authWithPassword(authCtrl.user) 
.then(function (auth){ 
    $state.go('home'); 
}, function (error){ 
    authCtrl.error = error; 
}); 
} 

authCtrl.register = function() { 
Auth.$createUserWithEmailAndPassword(authCtrl.user.email, authCtrl.user.password) 
.then(function (user){ 
    authCtrl.login(); 
}, function (error){ 
    authCtrl.error = error; 
}); 
} 

}); 

답변

2
+0

내 사람! 이 내가 createUserWithEmailAndPassword에 관해서 AngularFire 최신 버전의 소스 코드에서 발견 무엇 때문에 흥미 롭군요 : "* 작성 새 전자 메일/암호 사용자가이 기능은 사용자를 생성합니다 당신 을 경우. * 새로 만든 사용자로 로그인하려면 *이 방법이 해결 된 후 $ authWithPassword()를 호출하십시오. " 나는 그 논리를 그 자체의 함수로 사용하고 레지스터 내부에서 로그인 함수를 호출한다고 생각했다. 어느 쪽이든, 좋은 작품입니다. 많은 감사합니다. –

0

어쩌면 아론 손더스 AngularJS와 및 angularfire 사용하여 응답 무엇에 더 완전한 대답 건물 :

var auth = $firebaseAuth(); 

$scope.loginUser = function (email, password) { 
     auth.$signInWithEmailAndPassword(email, password).then(function(firebaseUser) { 
      console.log("User Logged in successfully with uid: " + firebaseUser.uid); 
     }).catch(function(error) { 
      console.log("An Authentication error occurred: " + error); 
     }); 
    }; 
관련 문제