Wednesday 29 April 2020

Why does this promise not return a value but pending?

async EmailExist(email) { let dbContext = new DbContext().Initialize("users"); let toReturn =false; let counter = 0; let promise = dbContext.where("email", "==", email).limit(1).get() .then((user) => { user.forEach(() => { counter++; }) }) .finally(() => { console.log(counter); if(counter !== 0){ return true; } else{ return false; } }); return await promise; } I need to check if email exists with firebase i limit the querry to 1 and if there is 1 user with that email i increase a counter i check if the counter is 1 and if it is i return a bool value that i use in my controller. Problem is when i log the methid i get promise pending not the value i want to return i tried with or withou await asyn i tried returning the value and changing it in the promise then but the change dosent register. It works when i log the counter in the promise but i cant return anything good to use in the controller.

Submitted April 29, 2020 at 09:42AM by draganov11

No comments:

Post a Comment