I have the following function:
export function readUserData(userName, password) {
firebase.database().ref("users/" + userName).once("value").then(function (snap) {
//console.log(snap.val().salt);
var verification = passwordVerify(password, snap.val().salt);
//console.log(verification);
//console.log(snap.val().password);
console.log(snap.val());
return snap.exists() && snap.val().password === verification
? userAuth.located = snap.val()
: userAuth.located = false;
});
return userAuth.located;
}
I am told that firebase.database().ref is an asynchronous function, and it seems to be so in that it returns userAuth.located in the final line of readUserData before writing console.log(snap.val());
How do I ensure that firebase.database().ref... executes before I return the final result? I am unsure how to implement await/promises into this code as the overall function is not asynchronous.