Undefined response to data.query

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.

Firstly, Wix already have their own Corvid Profile tutorial that will show member info after they have logged into the site.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

I’ve used the Wix Members app and that same tutorial on one of my websites and after the user signs themself up through my signup lightbox, the user is moved onto a signup status page with all their user inputs from my signup lightbox going into the Wix CRM and showing up in the Contacts List on the Wix Dashboard.

Then when the new site member is manually approved, those user inputs are then saved again into the Members dataset from the Corvid Profile tutorial where they will be shown to the user when they visit the profile page, where they can add, edit or change any info by using the provided user inputs.

Plus, have you seen Nayeli (Code Queen) youtube tutorial and website about a similar thing which searches for duplicate usernames when a member users the Wix tutorial for member profile page?

https://www.youtube.com/watch?v=yLCOqsVHhD0
https://codequeen.wixsite.com/membership-dashboard

I hadn’t seen the youtube tutorials you referenced and they are certainly useful. The process flow I require is slightly different from these examples, and I have based my implementation on the tutorial you mention. However, I did have a number of problems implementing that, particularly in the PromptLogIn displaying the WIX app sign on screen which is insufficient for my needs. Hence, the implemetation of a Corvid LightBox to handle the client side needs of registration and log on.

The WIX app already generates its own members dataset, Members/PrivateMembersData, which duplicates some information held in Contacts. My IT background abhors data duplication, so my memberProfile dataset is essentially just an extension table joined to the former.

After a bit more experimentation I suddenly realised my problem and it concerns handling the response from the Promise. I’d forgotten that the returned object could either be an array or an error object, and that it is essential to test to see how to handle the response. So, simply adding:

if (results.items.length === 0) {
throw new Error ("Missing PrivateMembersData record for uid = " + pUserId);
} else {
return results.items[0];
}

means that I don’t have the type mis-matches I was having.

Thanks for the feedback.

Trevor