loginprompt with signup not returning a user

Hello, when my site user clicks on a button to sign up, I prompt the default login page but I can't access any of their information to build an entry in my members collection. It gives the error, no user logged in. please help. the code is:

export async function btnSignUp_click(event) {
let myUser = await wixUsers.promptLogin( {"mode":"signup"});

let userid = myUser. id; //space added because the forum accused me of trying to post a link without it
let userEmail = await myUser.getEmail();

const toInsert = {
    "_id": userid,
    "memberEmail": userEmail
    }
    
wixData.insert("MemberInformation", toInsert);
}

I just get the error there is no logged in user.

thanks for any help

Hello @asyoung3000 ,

What your code is currently doing is simply adding the registration form data into a collection. However, it’s not registering the user therefore when you prompt the default login, there is no “user” to be found in the .

I suggest taking a look at the documentation for the register() function this will register the user and they then can use the default login but their data will be stored in the privateMembersData collection which is read-only. So to bypass this and collect more information then what the privateMembersData collection allows, create a reference field inside MemberInformation collection and reference the user either by code or manually selecting the user. This way the member and your row of extra data are then tied together.

Hi Brendan many thanks for your input. I think I get what you’re saying. The thing is, I thought I was using the wix default lightboxes for login and signup so assumed those handled the register() etc. How would I pass the email the user entered to the register() function when I seem to have no way to access it if it is entered into the default lightbox?

The weird thing is when I tried to understand it, I did a few console logs which confirm (after the default signup page has been completed) that there is a logged in user and I can display their id (they email also appears in my members list in the dashboard) but then when you run getEmail() it says there is no logged in user.

I had already decided last night to just bite the bullet and build custom login/sign up lightboxes. If as you say, coding is required even with the defaults then that definitely seems the way to go. It just makes me a bit nervous in case I miss an issue with my coding that wix’s version catches.

I have little choice though it seems…

thanks again for taking the time to help