Geeky Bird
Geeky Bird

Reputation: 71

$createUser(credentials) - Firebase creating a Clone of Slack

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


    });

Google Chrome console is throwing this 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)

I am thinking I need to go thru another tutorial. Things are outdated it seems. Can you please help me and let me know if I should continue using the same code and try to debug and change few things to make it work or start from scratch ?

Upvotes: 1

Views: 42

Answers (1)

Geeky Bird
Geeky Bird

Reputation: 71

Resolved with these

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

Upvotes: 1

Related Questions