My AngularJs + AngularFire setup includes email/password authentication and a node called "users" to list authenticated users. Here is a snapshot: https://i.sstatic.net/eBz3G.png
Within my authentication service, I have an AngularJs factory:
.factory('Auth', function($firebaseAuth, $firebaseObject, $firebaseArray){
var ref = firebase.database().ref();
var auth = $firebaseAuth();
var users = $firebaseArray(ref.child('users'));
var firebaseUser = auth.$getAuth();
var Auth = {
getStudent: function(studentId){
console.log(studentId)
return $firebaseObject(ref.child('users').child(studentId));
},
studentSignupProfile: function(profile){
console.log('Student profile service..!');
var obj = Auth.getStudent(firebaseUser.uid);
console.log(obj.name);
return obj.$loaded().then(function(){
obj.phone = profile.phone;
obj.address = profile.address;
return obj.$save();
});
}
};
return Auth;
});
This is the controller code:
$scope.studentSignupProfile = function(profile){
console.log(profile);
if (profile == undefined) {
toaster.pop('info','Tell us more about yourself!');
} else {
Auth.studentSignupProfile(profile).then(function(msg){
toaster.pop('info','Profile updated!');
$state.go('home');
});
}
}
The issue arises in console.log(obj.name) returning undefined despite the existing user UID as shown in the image above.
When I use the getStudent function with a specific uid like 4BAIdOXZv6NTEKsjgI15JTajFtz2, it logs the correct uid but retrieving the $firebaseObject results in undefined.