Looking for some help finding out where I went wrong with fetching the member ID then using the result to filter my collection query and sending the result as the body in my HTTP function. Everything works fine as a basic function but once I convert it to a get_ and add the headers and such I get an empty body or forbidden. The issue seems to be that the function that returns the member ID is null. Which means that it doesn’t wait for it to resolve the fetch before completing the GET. I tired await and it just returned forbidden 500. I have been at this for a week. I have watched and read everything and feel like I am missing something simple. Here is the code
export async function getUserID (params)
{
const fetchUserID = currentMember.getMember().then((member) => { const memberID = member._id; return memberID; }).catch((error) => { console.log(error) });
const _idResults = await fetchUserID;
return _idResults;
}
export function get_myGetMember(params)
{
let options =
{
"headers":
{
"Content-Type": "application/json"
}
}
return getUserID().then((results) =>
{
options.body ={ results }
console.log(results);
return results;
});
}
The functions have been tested outside of the get and they return the correct data. Even the method I setup to get the ID and then fetch the item from the database works. Just not in an HTTP function.
Returning just a simple query works, but the delay in fetching the member ID so that I can use it a filter(eq) is not working.
Code for that method is
export async function Fetch() { const fetchUserID = currentMember.getMember().then((member) => { const memberID = member._id; return memberID; }).catch((error) => { console.log(error) }); const idResults = await fetchUserID; const fetchProductID = await wixData.query(collection).eq("userID", idResults).find(); const productResults = fetchProductID.items[0].productId; return productResults; }