Problem with auto-create USER ID dynamic member page when a new user register. (RESOLVED)

Hello guys !

I’m using a custom registration form on a lightbox. Actually, when a new user sign up, a new contact is created in my Wix contact list and at the same time, a new line is created in my “MemberProfile” database with the same informations.
The point is, even if all looks great in the database, it seems that the registration is not complete because when the redirection time to the member profile dynamic page is coming, instead of seing MemberProfile/Update/ID page, I see a Wix error page “there is nothing here… We can’t find the page you are looking for. Check the URL, or head back home”.

Is there a smart guys to let me know where my code failed ?
Thanks A LOT.

import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;

$w.onReady( function () {

let user = wixUsers.currentUser;
let userId = user.id;

$w("#registerButton").onClick( (event) => { 

let email = $w(“#email”).value;
let password = $w(“#password”).value;
let first = $w(“#firstName”).value;
let last = $w(“#lastName”).value;

wixUsers.register(email, password, {
contactInfo: {
“firstName”: $w(‘#firstName’).value,
“lastName”: $w(‘#lastName’).value,
}
} )

  .then( () => { 

let toInsert = {
“prenom”: $w(“#firstName”).value,
“nom”: $w(“#lastName”).value,
“email”: $w(“#email”).value,
“_id”: userId,
};
wixData.insert(“MemberProfile”, toInsert)
. catch ( (err) => {
console.log(err);
wixLocation.to(/MemberProfile/Update/${wixUsers.currentUser.id});
} );

} );      
} ); 

});

EDIT : RESOLVED
Here is the right code that is working in my case :

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {

$w("#registerButton").onClick( (event) => { 

let email = $w(“#email”).value;
let password = $w(“#password”).value;
let first = $w(“#firstName”).value;
let last = $w(“#lastName”).value;

wixUsers.register(email, password, {
contactInfo: {
“firstName”: $w(‘#firstName’).value,
“lastName”: $w(‘#lastName’).value,
}

  } ) 

let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin( {“mode”: “signup”} )
.then( (user) => {

userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“MemberProfile”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail,
“prenom”: $w(“#firstName”).value,
“nom”: $w(“#lastName”).value,
};
// add the item to the collection
wixData.insert(“MemberProfile”, toInsert)
.then( () => {
wixLocation.to(/MemberProfile/Update/${wixUsers.currentUser.id});
. catch ( (err) => {
console.log(err);
} );
}

} )

  }      
 ); 

});

Just go to the members own profile page and not the members profile update page.

   wixLocation.to(`/MemberProfile/${wixUsers.currentUser.id}`); 

Also, check the code samples from both myself and Steve on your previous post about this.
https://www.wix.com/corvid/forum/community-discussion/how-to-create-database-entries-when-a-user-sign-up/p-1/dl-5cf5ae97d649b4034c6819a8

Also, remember that this update page is site member author read only, so nobody else will be able to see the member profile update page or the member profile page.

Plus, it needs to be tested on a live and published website and not just through your preview.

So, test and result : I tried your idea by removing “Update” but first, it still doesn’t work and worst, it stopped to had the infos in my MemberProfile database. So the right way was the first solution, to let the “Update”. But crap ! I don’t found where the bug is…

Yes, I read and re-read your previous post on my other topic and try to implemant it in my case but still no good results…

And yes, I know for the readable only by author and preview mode. All my test were live.

Really, this bug seems to be mysterious for me.