$createUser(凭据) - Firebase 创建 Slack 克隆



https://thinkster.io/tutorials/angularfire-realtime-slack-clone/creating-the-auth-controller

/* 身份验证服务 */

angular 
.module('angularfireSlackApp')
.factory('Auth', function($firebaseAuth, FirebaseUrl){
var ref = firebase.database().ref();
var auth = $firebaseAuth();
return auth;
});

/* 身份验证控制器*/

angular.module('angularfireSlackApp') 
.controller('AuthCtrl', function(Auth, $state){
var authCtrl = this;
authCtrl.user = {
email:'',
password:''
}
authCtrl.login = function(){
Auth.$authWithPassword(authCtrl.user).then(function (auth){
$state.go('home');
}, function(error){
authCtrl.error = error;
});
};
authCtrl.register = function(){
Auth.$createUser(authCtrl.user).then(function (user){
authCtrl.login();
}, function(error){
authCtrl.error = error;
});
};

});

谷歌浏览器控制台正在抛出此错误。

TypeError: Auth.$authWithPassword is not a function
at Object.authCtrl.login (auth.controller.js:13)
at fn (eval at compile (angular.js:15500), <anonymous>:4:179)
at callback (angular.js:27285)
at ChildScope.$eval (angular.js:18372)
at ChildScope.$apply (angular.js:18472)
at HTMLFormElement.<anonymous> (angular.js:27290)
at defaultHandlerWrapper (angular.js:3771)
at HTMLFormElement.eventHandler (angular.js:3759)
This is for the login.
& For the register.
TypeError: Auth.$createUser is not a function
at Object.authCtrl.register (auth.controller.js:22)
at fn (eval at compile (angular.js:15500), <anonymous>:4:182)
at callback (angular.js:27285)
at ChildScope.$eval (angular.js:18372)
at ChildScope.$apply (angular.js:18472)
at HTMLFormElement.<anonymous> (angular.js:27290)
at defaultHandlerWrapper (angular.js:3771)
at HTMLFormElement.eventHandler (angular.js:3759)

我想我需要通过另一个教程。事情似乎已经过时了。你能帮帮我,让我知道我是否应该继续使用相同的代码并尝试调试和更改一些东西以使其工作或从头开始吗?

用这些解决

authCtrl.login = function (){
Auth.$signInWithEmailAndPassword(authCtrl.user.email, authCtrl.user.password).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){
$state.go('home');
}, function (error){
authCtrl.error = error;
});
};

最新更新