Query runs correctly in Wix but not chrome

I am having difficulty understanding why the following code works when using the Wix debugger. Its a form to enter email. I am trying to determine if the email is in the site members database. The code is incomplete, trying to get past the first hurdle of getting data from the members database.
When run in Wix, it acts as expected, returns a result if there’s a match. However when running in Chrome, the result is always nothing or not defined, the count is 0.

Any help appreciated.

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixData from 'wix-data';

async function verifyEmail(email) {
    let options = {
        "suppressAuth": true,
        "suppressHooks": true
    };
    //debugger;
    let myResult = await wixData.query("Members/PrivateMembersData")
        .eq("loginEmail", email)
        .find(options)
        .then((results) => {
        debugger;
        console.log("count = ", results.items.length);
            if (results.items.length > 0) {
                let items = results.items;
                let firstItem = items[0];
                console.log("Email found.");
            } else {
                // handle case where no matching items found
                console.log("Email NOT FOUND.");
            }
        })
        .catch((error) => {
            debugger;
            let errorMsg = error.message;
            let code = error.code;
        });;
        let another = myResult;
}


$w.onReady(function () {
    $w('#loginNow').onClick(function () {
        let email = $w('#loginEmail').value;
        let password = $w('#loginPassword').value;
        //
// test code
        verifyEmail(email);

// end test code

//  org below
        wixUsers.login(email,password)
        .then(() => {
            wixLocation.to('/Home')
        })
    })
});
1 Like

It’s because in preview mode the code runs as admin and in a user’s browser it doesn’t because you don’t want your regular users able to query PrivateMembersData.

Here it seems like the code is doing client side validation of emails. This code would be better placed in a backend function and handling whatever logic you need there without exposing it to users. This doc explains how and why to do so:

However in this case there’s also no need to verify a user’s email before logging in. wixUsers.login() will do all the necessary verification.

1 Like

Got it. The query code must be on backend. I moved it and it works!
Login understood, the plan is to do something else, my verify just happens to be in this test page.
Thanks for the help!

1 Like

Welcome! Happy to help!