I am trying to write a website with chat, file storage etc. I am using JS and Google Firebase. The problem is that I'd like to check if the user already exists, I wrote a function to check this, but it seems not to work. I can console.log the value (and this works fine) but I cannot return the value (every time it shows that the variable is undefined).
Here is my code:
function checkIfTheUserExists(user)
{
db.ref("messages/" + user).once("value").then(function(snapshot) {
const ifPathExists = snapshot.exists();
console.log(ifPathExists);
});
}
When I am trying to return the value of ifPathExists it always shows undefined, even when I am trying to assign the value to another variable.
Please use straightforward explanation that I can easily understand.