【问题标题】:$createUser(credentials) - Firebase creating a Clone of Slack$createUser(credentials) - Firebase 创建 Slack 的克隆
【发布时间】:2017-07-22 09:44:48
【问题描述】:

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


    });

Google 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)

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

【问题讨论】:

    标签: javascript angularjs git firebase


    【解决方案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;
      });
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      相关资源
      最近更新 更多