Delay accessing member data?

Hi guys,

I’m having an odd experience when someone access one of my pages that uses the “Members/PrivateMembersData” collection.

When a user wants to book one of my services I make them login or create an account. After they have logged in I bring them to a custom form to enter in required data. Some of the data is pre-populated from the “Members/PrivateMembersData” collection. All of this works but has issues with getting the variables from the “Members/PrivateMembersData” collection.

Here is the scenario:

  1. User comes to my site and clicks Book Now. This executes the below code that will check if they are logged in or not. If logged in it will open the lightbox. If not logged in, it will have them log in and then open the light box.

if (continueBooking === 1){
 if(wixUsers.currentUser.loggedIn) {
 //setTimeout(
 await wixWindow.openLightbox(openPrompt, passData)
                    .then( (data) => {
                        console.info('LightBox Closed');
                        console.info(data)
                        processBookingAction(data, $w("#table1"));
 
                    } //),1000
                    )
                }
 else {
 await wixUsers.promptLogin( {"mode": "login"} )
                        .then( (user) => {
 //setTimeout(
                            wixWindow.openLightbox(openPrompt, passData)
                            .then( (data) => {
                                console.info('LightBox Closed');
                                console.info(data)
                                processBookingAction(data, $w("#table1"));
 
                            } //),1000
                            )
                        } )
                }
 
            } 
  1. Next, the lightbox will open and gather data from the “Members/PrivateMembersData” collection to pre-populate the firstname, lastname, etc on the booking form.
async function getUserDetails() {
    user = await wixUsers.currentUser;
    await user.getEmail()
        .then( (email) => {
            userEmail = email;     
            userId = user.id;          
            setUserInfo(userId);
        } );
}

async function setUserInfo(userId) {
 await wixData.query("Members/PrivateMembersData") 
        .eq("_id", userId)
        .find() 
        .then( (results) => { 
		firstName = results.items[0].firstName; 
                lastName = results.items[0].lastName;
                phoneNumber = results.items[0].mainPhone;
        } );
}

Now the problem occurs here. If the user comes to my page with a new session (new user or returning user) and clicks the Book Now button for the first time the data for the firstname, lastname, etc is “blank”. However if the user clicks the Book Now button again (second time) the data for firstname, lastname is now available.

On another page I have a intermediate lightbox that pops up to give the user options between these two code snippets. This intermediate lightbox seems to cause enough of a delay that I get data back on the user first click of the Book Now button.

With the above in mind, do I need to cause a delay after the user logs in before I can access the “Members/PrivateMembersData” collection??

Thank you for your help!

I figure this out.

I was referring to a session item inside of my query to the “Members/PrivateMembersData” collection that did not exist when the user was new.