Why won't my query wait for the values to change?

  1. My goal: I'm currently just trying to get a basic log-in system working by storing the username and password variables in MongoDB and using an API to read them in and compare the user's inputs with the usernames and passwords on file. I want to have it so when the "Log-In" button is pressed, it triggers the query, and then changes to a different page depending on the permissions of the user pulled.
  2. Issue: For some reason I always need to click the button twice as the first one results in the query returning with null even when the variables for username and password are correct.
  3. Steps I've taken to troubleshoot: I've tried using a variable as a temporary state for the username and password and forcibly waiting for those to set before running the query but that didn't work. I also tried using the onSuccess function built into the setValue functions but that also didn't work.
  4. Additional info:

What's the run behaviour of your query?

From what I see, it appears you are mixing two different ways to handle the success of the query.

try getting the data in the callback

checks_log_in.trigger({
  onSuccess: function(result) {
    console.log(result);
    // ....
  }
})

OR

use await

const result = await checks_log_in.trigger();

console.log(result);
// ....
1 Like

I'm not sure what I did wrong last time I tried pulling the result through the onSuccess function but this time it worked perfectly. Thank you @khill-fbmc!