[Solved] Validation between input and database not working

Hi there!
I am really struggling with this issue:
I have an input field (input 10) where the user has to enter an activation code that he/she received. I have a database (called CardActivationCodes) where the activation codes are stored and matched to the email adresses.
With onChange of input 10 I would like to get the logged-in-users email adresse and confirm that the activation code in input 10 matches the code I have for this email adress in the database.

The problem: It worked with my test email adress but it does not work for any other email adress. And I can not figure out why… Does anyone spot an issue in the code?
I checked the Field-Key about 20 times. I know that the problem must be at the first steps of the query part…
Thanks so much for your help!

export function input10_change(event) {
 //Add your code for this event here: 

let activationcode = $w("#input10").value
wixUsers.currentUser.getEmail().then((email) => {
wixData.query("CardActivationCodes")
    .eq("emailAddress", email)
    .find()
    .then(res => {
 if (res.length === 0) {
      }
 else 
 if (res.items[0].cardActivationCode === $w('#input10').value) {
        $w("#button6").enable(); 
          $w("#checkbox1").enable();
          $w("#text60").hide();
      }
 else {
        $w("#text60").show();
      }
    })

}             
).catch((err) => {
let errorMsg = err;
})
}

 

Hi Robin, when testing, unless you are logging into the web site as these other users, the record that is being returned every time with the getEmail function is going be your record.

Thank you anthonyb! You are right! I tested it also in the live web site with other emails but could not find the problem. I just figured it out and will post my issue here! Thanks again for your fast support!

I figured out what the issues was:
The code works fine but the issue was with the privacy settings of my database collection. It was obviously restricted to access by admin only. I changed it the being readable by “Members” and now it works. That was quite stupid but I am glad I figured it out!
Thanks for your support, Community!