I am trying to check if a user is logged in and return true or false based on that. But the function return before the firebase call is completed.
async function checkLogin() {
var result;
await firebase.auth().onAuthStateChanged(function(user) {
if (user) {
result = true;
console.log("user is signed in");
} else {
result = false;
console.log("user is not signed in");
}
});
console.log("End of function");
return result;
}
"End of function" gets printed out before any of the above two. The value in result is always undefined. It seems the function returns before the completion of firebase.auth(). Is there a way I can make it wait before returning.