Whenever my program attempts to modify exists in the firebase function, the obtained value is temporary. I want to be able to return true or false at the end of this function.I have seen a few related posts and nothing seems to be working. Making exists global and separating the snapshot function didnt work. Any advice?
function checkIfUserExists(userId) {
var exists;
var usersRef = firebase.database().ref("users");
usersRef.child(userId).once('value').then(function(snapshot) {
exists = (snapshot.val() !== null); // exists is true or false
userExistsCallback(userId, exists);
});
return exists; //exists is undefined
}