I am attempting to write a bespoke membership registration and log in scheme on top of the existing WIx Members system. The Wix part works ok, the .login(email,password) command in a lightbox successfully updates the entry in the Members/PrivateMemberData collection. However, I have a Site based event handler for the onLogIn event which I’m trying to use to check whether that user exists also in a second collection, memberProfile, that I will be using to handle site specific user information.
My problem is that when I issue the command:
const results = await wixData.query(“memberProfile”)
.eq(“_id”, pUserId)
.find();
I’m getting a success promise response, but the results returns as Undefined Undefined.
Why? I’m tearing my hair out trying to get to read these datasets.
Relevant code snippets are:
wixUsers.onLogin( async (user) => {
let isLoggedIn = user.loggedIn;
let userId = user.id;
let userRole = user.role;
let mtcbcRole;
let userEmail;
let fullName;
console.log("onLogin: "+ userRole);
console.log("before findmember async call “);
try {
const item = await findMember(userId);
fullName =item.firstName + " " + item.lastName;
console.log(“after findmember async call”);
}
catch (error) {
console.log(“findmember call Try Catch 2” + error);
}
local.setItem(“userId”, user.id);
local.setItem(“userRole”, user.role);
local.setItem(“mtcbcRole”, mtcbcRole);
local.setItem(“userEmail”, userEmail);
local.setItem(“fullName”, fullName);
console.log(“After async call " + fullName);
wixLocation.to(wixLocation.url); //This reloads the same page and allows code to show hidden member parts.
});
async function findMember(pUserId) {
console.log(“Inside async” + pUserId);
try {
const results = await wixData.query(“memberProfile”)
.eq(”_id”, pUserId)
.find();
console.log(“inside findmember, after data query”);
return results;
}
catch (error) {
console.log("TryCatch " + error);
}
}
and the console l og generated running this shows:
onLogin: Member wixcode-worker.js:18:102256
lbxLogIn1 : User is logged in wixcode-worker.js:18:102256
before findmember async call wixcode-worker.js:18:102256
Inside async80ab4800-eb00-41d3-970a-0a24adbb0fc4 wixcode-worker.js:18:102256
Log In lightbox success wixcode-worker.js:18:102256
inside findmember, after data query wixcode-worker.js:18:102256
after findmember async call wixcode-worker.js:18:102256
After async call undefined undefined wixcode-worker.js:18:102256
Navigated to https://allentrev88.wixsite.com/mtbcold
map callback google-map.js:607:13
On ready wixcode-worker.js:18:102256
on readylooged in wixcode-worker.js:18:102256
Any help or guidance would be gratefully received.