{"action":"created","issue":{"url":"https://api.github.com/repos/planetoftheweb/angulardata/issues/3","labels_url":"https://api.github.com/repos/planetoftheweb/angulardata/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/planetoftheweb/angulardata/issues/3/comments","events_url":"https://api.github.com/repos/planetoftheweb/angulardata/issues/3/events","html_url":"https://github.com/planetoftheweb/angulardata/issues/3","id":57030601,"number":3,"title":"Problem in Authentication.login(user)","user":{"login":"imieites","id":5364929,"avatar_url":"https://avatars.githubusercontent.com/u/5364929?v=3","gravatar_id":"","url":"https://api.github.com/users/imieites","html_url":"https://github.com/imieites","followers_url":"https://api.github.com/users/imieites/followers","following_url":"https://api.github.com/users/imieites/following{/other_user}","gists_url":"https://api.github.com/users/imieites/gists{/gist_id}","starred_url":"https://api.github.com/users/imieites/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imieites/subscriptions","organizations_url":"https://api.github.com/users/imieites/orgs","repos_url":"https://api.github.com/users/imieites/repos","events_url":"https://api.github.com/users/imieites/events{/privacy}","received_events_url":"https://api.github.com/users/imieites/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-09T13:31:58Z","updated_at":"2015-02-09T20:40:42Z","closed_at":"2015-02-09T20:40:42Z","body":"Hello,\r\n\r\nIn the login function of the Authentication service, I see the 'user' variable passed as parameter only contains the email and password of the user we want to login. But on the 1st line of the function I see that we're trying to set userRef by using 'user.uid'. The problem I see in my test is that user.uid is undefined at this point. Am I missing something?\r\n\r\n```\r\nlogin : function(user) {\r\n      var userRef = new Firebase(FIREBASE_URL + '/users/' + user.uid);\r\n      var userObj = $firebase(userRef).$asObject();\r\n...\r\n```\r\nA solution I found is authenticating first (I'm using firebaseAuth instead of SimpleLogin), and the promise of that returns the user data we need, including the uid, so now it can be used. Something like this...\r\n\r\n```\r\n        login : function(user) {\r\n\r\n            return authObj.$authWithPassword({\r\n                email: user.email,\r\n                password: user.password\r\n            })\r\n            .then(function(authData){ \r\n                console.log('authentication.js: logged in user '+ authData.uid);\r\n\r\n                var userRef = new Firebase(FIREBASE_URL + 'users/' + authData.uid);\r\n                var userObj = $firebase(userRef).$asObject();\r\n\r\n                userObj.$loaded().then(function() {\r\n                    $rootScope.currentUser = userObj;\r\n                });\r\n\r\n                $rootScope.$broadcast('$firebaseAuth:authWithPassword',authData); // avisa al scope\r\n\r\n              return authData;\r\n          });\r\n```"},"comment":{"url":"https://api.github.com/repos/planetoftheweb/angulardata/issues/comments/73585647","html_url":"https://github.com/planetoftheweb/angulardata/issues/3#issuecomment-73585647","issue_url":"https://api.github.com/repos/planetoftheweb/angulardata/issues/3","id":73585647,"user":{"login":"planetoftheweb","id":216426,"avatar_url":"https://avatars.githubusercontent.com/u/216426?v=3","gravatar_id":"","url":"https://api.github.com/users/planetoftheweb","html_url":"https://github.com/planetoftheweb","followers_url":"https://api.github.com/users/planetoftheweb/followers","following_url":"https://api.github.com/users/planetoftheweb/following{/other_user}","gists_url":"https://api.github.com/users/planetoftheweb/gists{/gist_id}","starred_url":"https://api.github.com/users/planetoftheweb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/planetoftheweb/subscriptions","organizations_url":"https://api.github.com/users/planetoftheweb/orgs","repos_url":"https://api.github.com/users/planetoftheweb/repos","events_url":"https://api.github.com/users/planetoftheweb/events{/privacy}","received_events_url":"https://api.github.com/users/planetoftheweb/received_events","type":"User","site_admin":false},"created_at":"2015-02-09T20:40:42Z","updated_at":"2015-02-09T20:40:42Z","body":"Hi there,\r\n\r\nYes. Unfortunately, this course was built with the old version of SimpleLogin. The changes to the new service are quite dramatic.\r\n\r\nThankfully, I just finished re-recording the course for the new authentication service. It will take a while before it goes live, but you can check out all of the code at this URL\r\n\r\nhttp://github.com/planetoftheweb/angulardatau\r\n\r\nTo answer your specific questions, you can use events to make sure that the authentication process has completed. You can use $getAuth or $onAuth (https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-users-and-authentication-getauth), but there's a better way that I show in the new video, which is to handle pre-verification through your routes. \r\n\r\n```\r\n    when('/meetings', {\r\n      templateUrl: 'views/meetings.html',\r\n      controller: 'MeetingsController',\r\n      resolve : {\r\n        currentAuth: function(Authentication) {\r\n          return Authentication.requireAuth();\r\n        }\r\n      }\r\n    }).\r\n```\r\n\r\nYou can catch potential authentication errors like this:\r\n\r\n```\r\nmyApp.run(['$rootScope', '$location', function($rootScope, $location) {\r\n  $rootScope.$on('$routeChangeError',\r\n  function(event, next, previous, error) {\r\n    if(error === 'AUTH_REQUIRED') {\r\n      $rootScope.message='Sorry, you must log in to access that page';\r\n      $location.path('/login');\r\n    }\r\n  });\r\n}]);\r\n```\r\n\r\nHere's my new app.js file:\r\nhttps://github.com/planetoftheweb/angulardatau/blob/master/builds/development/js/app.js\r\n\r\nAnd my new Authentication service\r\nhttps://github.com/planetoftheweb/angulardatau/blob/master/builds/development/js/services/authentication.js\r\n\r\nHopefully that helps.\r\n\r\n"}}