Thank you very much for replying russian-dima, Code Queen Nayeli, shimonsuissa1954… I really appreciate it! ![]()
Actually, I based my code to this youtube link: https://www.youtube.com/watch?v=o1gc-baNMrY&t=429s
Thanks to Code Queen Nayeli!
And added a let toSave code inside the function registerPerson().
Thanks to russian-dima!
This is the whole code of my sign up lightbox. I believe I will put the additional code inside the function registerPerson(), but I don’t know where and what code exactly to put there that could insert the contactId , which is in the PrivateMembersData, to the _id inside my own database.
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
let registration;
$w.onReady(function () {
if (wixUsers.currentUser.loggedIn) {
wixLocation.to(`/member/my-profile/${wixUsers.currentUser.id}`); //Change the URL ending to the page you want to redirect the user if they are already logged in
}
$w("#password").onKeyPress((event) => {
let key = event.key;
$w('#errorMessage').hide();
$w('#emailExists').hide();
if (key === "Enter") {
console.log("Pressed Enter key on Password field"); //You can change the text of this line or delete it
if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
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": first,
"lastName": last
}
})
.then(()=>{
$w("#successful").show();
wixLocation.to("/member/welcome-new-user")
//Change the URL ending to the page you want to redirect the user after they successfully register
.catch((err) => {
let errMsg = err;
});
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
$w('#emailExists').show();
});
} else {
console.log("Some inputs are invalid"); //You can change the text of this line or delete it
$w('#errorMessage').show();
}
} else {
console.log("Did not press Enter key."); //You can change the text of this line or delete it
}
});
$w("#registrationButton").onClick((event) => {
console.log("Button was clicked"); //You can change the text of this line or delete it
$w('#errorMessage').hide(); //We want to hide all error messages when the person attempts to register again
$w('#emailExists').hide(); //We want to hide all error messages when the person attempts to register again
if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
registerPerson();
console.log("Trying to register"); //You can change the text of this line or delete it
} else {
$w('#errorMessage').show(); //This is were we prompt the message to show up again ONLY if there is an error
console.log("Missing information"); //You can change the text of this line or delete it
}
});
});
function registerPerson() {
let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#firstName").value;
let last = $w("#lastName").value;
let userId = wixUsers.currentUser.id;
wixUsers.register(email, password, {
contactInfo: {
"firstName": first,
"lastName": last
}
})
.then(() => {
let toSave = {
"emailAddress": email,
"password": password,
"firstName": first,
"lastName": last,
};
wixData.save("MemberPage", toSave)
})
.then(() => {
$w("#successful").show();
wixLocation.to("/member/welcome-new-user");
//Change the URL ending to the page you want to redirect the user after they successfully register
})
.catch((err) => {
let errorMsg = err;
console.log(err);
$w('#emailExists').show(); //This is were we prompt the message to show up again ONLY if there is an error
});
}