javascript - firebase simple login tutorial missing user -


tutorial: http://www.thinkster.io/angularjs/wbhtrlwhir/6-authenticating-users-with-a-service

i'm following tutorial , seems i'm losing user register.

here auth.js factory:

'use strict';  app.factory('auth', function($firebasesimplelogin, firebase_url, $rootscope){      var ref = new firebase(firebase_url);      var auth = $firebasesimplelogin(ref);      var auth = {         register : function(user) {             return auth.$createuser(user.email, user.password);         },         signedin : function() {             // problem: authuser null             console.log(auth.user);             return auth.user !== null;         },         logout : function () {             auth.$logout();         }     };      $rootscope.signedin = function () {         return auth.signedin();     };      return auth; }); 

here auth.js controller:

'use strict';  app.controller('authctrl', function($scope, $location, auth){     if (auth.signedin()) {         $location.path('/');     }      $scope.register = function () {         auth.register($scope.user).then(function (authuser) {             console.log(authuser);             $location.path('/');         });     }; }); 

the console.log under signedin in factory null. idea disconnect is? registration working fine, , authuser populated in console.log in controller when registering.

the latest documentation angularfire says $createuser method of $firebasesimplelogin returns promise doesn't mention any parameters being passed then callback.

you can use $getcurrentuser method current user after user registers.

the tutorial needs updated , should always checking documentation whatever libraries you're using yourself.

your code signedin should this:

auth.signedin = function() {     auth.$getcurrentuser().then(function(currentuser) {         console.log(currentuser);     }, function() {         console.log('error');     }); }; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -