My frontend page is calling a function which does a DB lookup and returns a boolean value based on it’s findings. But what’s happening is that the script is running past the lookup and I’m getting undefined errors.
backend\somefile.js(w) ++++ I tried both public and backend, neither work.
export function userSubCheck(em, sub) {
wixData.query(“Members”)
.eq(“email”, em) // em = email address
.find()
.then( (results) => {
let answer = false;
let check = results[“_items”][0][sub]; // sub = boolean
if (check) {
console.log(“Is Subscribed”);
answer = true;
}
return answer;
} )
.catch( (err) => {
console.log(err);
} );
}
=======================================================
Frontend code doing the calling, I get console errors on here…
import {userSubCheck} from ‘public/userSubCheck.js’; //or backend/, neither work.
let checkCat = session.getItem(“subCheck”);
let userEmail = session.getItem(“email”);
$w.onReady(function () {
userSubCheck(userEmail,checkCat).then(status => {
console.log(status);
});
});