Custom Member Profile page locked

I have a custom members database called MemberInfo2. When a user goes to the My Member Profile (inside the Members section) page the code checks to see if they are an existing member.

  • If they are not in our database, they complete their profile form and it creates a new user in the MemberInfo2 database.
  • If they are an existing member, they can update their profile and it saves to the MemberInfo2 database.

This page has been working for about a week. Members are able to sign up and update their profiles. However, some users (myself and the owner) are not able to edit our profiles. I see this message in the site log and when I test locally.

"You have unhandled error in async operation. Consider catching it and handling accordingly.  DatasetError: There is no current item"

Any ideas on how to fix it?

Many thanks,
Sylvia

This is my profile page code:


import wixData from 'wix-data';
import wixUsers from 'wix-users';

let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn; // true
let pId;
let pUser;
let pEmail;
let p1FirstName;
let p1LastName;
let m1DefaultImage = "https://static.wixstatic.com/media/5da86a_8430e6dafcb8498aae9821f3ce5d52f0~mv2.jpg";

$w.onReady(function () {
wixData.query("Members/PrivateMembersData")
        .eq("_id", userId)
        .find()
        .then((results) => {
            // let pUser = results.items[0].user;
            let pId = results.items[0]._id;
            let pEmail = results.items[0].loginEmail;
            let p1FirstName = results.items[0].firstName;
            let p1LastName = results.items[0].lastName;
            

            console.log("PrivateMembersData userId = " + userId);
            console.log("PrivateMembersData pId = " + pId);
            console.log("PrivateMembersData pEmail = " + pEmail);
           
            $w('#mEmail').text = pEmail;
           

            $w("#MemberInfo2").onReady(() => {
                wixData.query("MemberInfo2")
                    .eq("_id", pId)
                    .find()
                    .then((results) => {
                        // console.log("MemberInfo query pId = " + pId);
                        // console.log("MemberInfo query userId = " + userId);
                        // console.log("MemberInfo query pEmail = " + pEmail);

                        if (results.items.length === 0) {
                            const toInsert = {
                                "_id": pId,
                                "mEmail": pEmail,
                                "m1FirstName": p1FirstName,
                                "m1LastName": p1LastName
                            }
                            // Add these items to the member database collection
                            wixData.insert('MemberInfo2', toInsert)
                                .then((results) => {
                                    let item = results; 
                                //see item below
                                    // console.log("MemberInfo insert userId = " + pId);
                                    // console.log("MemberInfo insert vEmail = " + pEmail);
                                    
                                })

                                .then((results) => {
                                    $w('#MemberInfo2').save();
                                })
                                .then(() => {
                                    MemberInfo2Refresh();
                                })

                                .catch((err) => {
                                    let errorMsg = err;
                                    $w('#error').text = errorMsg;
                                    console.log("insert=" + errorMsg)
                                });

                        }

                        if (results.items.length > 0) {

                            console.log("122 MemberInfo query pId = " + pId);
                            console.log("124 MemberInfo query pEmail = " + pEmail);

                            //Give the (database fields) a variable name
                            //M1
                            
                            let v1ProfileText = results.items[0].m1ProfileText;

                            MemberInfo2Refresh();

                            if (v1Image) {
                                $w('#m1Image').show();
                            } else {
                                let m1DefaultImage = $w("#m1Image").src = "https://static.wixstatic.com/media/5da86a_8430e6dafcb8498aae9821f3ce5d52f0~mv2.jpg";
                            }

                            // Connect the page inputs to M1 variables 
                            //(this will pull the current database content in the page input fields)
                           
                            $w('#m1ProfileText').value = v1ProfileText;

                            //set M1 database fields (FieldNames) to the variables 
                            //(This will save the page input field text to the database)
                            $w("#MemberInfo2").setFieldValues({
                                 "_id": pId,
                                "mEmail": pEmail,
                                "m1FirstName": p1FirstName,
                                "m1LastName": p1LastName,
                                "m1ProfileText": v1ProfileText
                            })
the rest of the code ... 

so turns out my page was locking because of this code:

.then((results)=>{$w('#MemberInfo2').save();})
.then(()=>{MemberInfo2Refresh();})

wIX support told me to put the refresh code inside and after the save code, then it worked:

 .then((results) => {
 $w('#MemberInfo2').save()
    .then((results) => {                                                $w('#MemberInfo2').refresh();
                       })
                  })