So I have a function in my react native app that needs to check a code entered by the user and compare it to one in the firebase-realtime-database. Currently, I am using a forEach loop to cycle through the code in the db, and comparing them to the entered code. The problem is, a return statement seems to have no effect on this code segment, and it always runs all the way through. I am a total beginner to this, so if there is a better way to do it, I am completely open minded. Here is the problematic code :
function checkCode(text) {
var code = text;
codesRef.once('value', function(db_snapshot) {
db_snapshot.forEach(function(code_snapshot) {
if (code == code_snapshot.val().value) {
console.log("Authentication Successful!");
// break; // throws error
return; // Does not seem to stop the code segment
}
})
console.log("Authentication Failed!"); // This still runs, even on success...
//AlertIOS.alert("We're Sorry...", "The code you entered was not found in the database! Please contact Mr. Gibson for further assistance.")
});
}
The code for my AccessForm.js is below, and I am open to any suggestions, even if it isn't related to the forEach issue.
DropBox : AccessForm