I would like to check recursively if a node exist in Firebase (created by cloudfunction), I tried many things but I'm a bit lost between promises, callbacks etc and I can't make it work.
Here is what I tried (in a auth service) :
checkifExist(userId:string){
const self=this;
firebase.database().ref('/users/'+userId).once('value', function(snap) {
return true;
}, function(error) {
console.log("user not yet created by CF :"+error);
// wait 2 seconds before to try again
setTimeout(() =>{
self.checkifExist(userId);
},2000);
});
and I call it in a component with :
if(this.auth.checkifExist(userId)){
// code if success
}
Problem :
the code if success is never executed, because :
this.auth.checkifExist(userId) is undefined
why? Any idea?