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);
} );
}
} )
}
);
});