1

I have this simple promise:

function getprofile(id) {
  if(firebase.auth().currentUser){
    firebase.database().ref('votes/' + id + '/' + firebase.auth().currentUser.uid)
    .once('value')
    .then(function(snapshot) {
      if (snapshot.exists()){
        console.log('ok1');
        return '<span>user exists</span>';
      }else{
        console.log('ok2');
        return '<span>user doesn\'t exist</span>';
      }
    });
  }else{
    console.log('ok3');
    return '<span>you must be logged</span>';
  }
}

But when I call it, instead of returning a span, the function returns "undefined" even though my console log works

woshitom
  • 4,811
  • 8
  • 38
  • 62
  • you need to return the original promise; add `return` to `firebase.database()`. Also for the `else` statement, it should be returned as a Promise, `return Promise.resolve('you must be logged');` – Kousha Jul 22 '19 at 17:46
  • thank you for your answer @Kousha Well, when I do so the output is now [object Promise] :( the console.log is still happening though, and thanks for the last part :) – woshitom Jul 23 '19 at 05:30

0 Answers0