$ createUser(credentials) - Firebase创建Slack克隆

时间:2017-07-22 09:44:49

标签: javascript angularjs git firebase

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

/ * AUTH SERVICE * /

angular 
    .module('angularfireSlackApp')
    .factory('Auth', function($firebaseAuth, FirebaseUrl){

    var ref = firebase.database().ref();
    var auth = $firebaseAuth();

    return auth;

});

/ * AUTH CONTROLLER * /

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;
            });
        };


    });

谷歌Chrome控制台正在抛出此错误。

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)

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

1 个答案:

答案 0 :(得分:1)

解决了这些

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;
  });
};