lundi 19 août 2019

Firebase web. Returning Promise

This question already has an answer here:

I am trying to get the current score of a specified user. However, instead of returning the score I am getting (in the console):

enter image description here

the current score in my firebase database is 3. Here is the function I have:

function getCurrentScore() {

    var userId = firebase.auth().currentUser.uid;
    return firebase.database().ref('/users/' + userId).child('score').once('value').then(function(snapshot) {
        console.log(snapshot.val());
    });

}

what I want to do is assign the value to a variable that I can use. For example

var score = getCurrentScore();

How can I get this value and assign it to a variable in firebase?




Aucun commentaire:

Enregistrer un commentaire