I am having an issue (new to JavaScript and ionic) regarding Firebase database. I have a code to display the name of a user :
.controller('accountController',['$scope', '$firebaseArray', 'CONFIG', '$document', '$state', function($scope, $firebaseArray, CONFIG, $document, $state) {
var userId = '-KcsNqRpO70spcMIPaKg';
return firebase.database().ref('/accounts/' + userId).once('value').then(function(snapshot) {
var displayName = snapshot.val().name;
$scope.$apply(function() {
$scope.displayName = displayName;
});
console.log(displayName);
// ...
});
}])
This works fine when I use directly the -KcsNqRpO70spcMIPaKg, but I would like my code to get directly this string by simply matching the logged in user to its account in the database.
I tried using var userId = firebase.auth().currentUser.uid; instead, but it doesn't grab the -KcsN..., instead it grabs the actual uid from the authentication.
I am lost. I do not understand how to grab it. Any ideas?