How can I wait for function to finish?

Hey
I have some functions that work but sometimes they stop. I have no idea what I do wrong so please help me gurus.

The below function will query data collection Members and search for facebookId and return the whole object if found.

async function getMember(userid) {
	return wixData.query('Members')
	.eq("facebookId",userid)
	.find()
	.then( (result) => {
			// Results from members
			if (result.totalCount > 0) {
				return  result.items[0];
			}
		})
	.catch( (err) => {
		console.log (err);
		} 
	);
}

In the calling function below I want to wait for the function to finish but this does not seem to work in all cases.

$w.onReady(async function () {
	member = await getMember("76767676767676"); // Correct userId
	console.log(member);
});

Any ideas?

Hi Andreas,
The code looks ok.
Can you please share a link to your page so we can inspect ?
Roi

https://www.frej.ai/Members/1716044581791186

Hi Andreas,
It’s working in my end:
I added console.log to test it.


And it prints:


I didn’t change anything.
Roi