Hi all.
I am having a problem with the site registration functions
I have a form working OK and it properly registers the info entered in both the members collection and another collection (without the password field) but I am having trouble with handling exceptions.
The API says that it will automatically put up a notification and email the user that the address has already been used on the site but it doesn’t do so…I can see the error in the console but no notification on screen or in my email. So I have added error handling in the subReg() function to determine the error status and show an error message…but I don’t understand why the API states this is automatic when it isn’t.
Also, on success now, authentication . register() automatically opens a generic success lightbox over the top of the register window…when I really want to close the register lightbox first. When the generic success lightbox pops up, it halts the entire function…meaning that the registartion window is open below it still. I am just looking for a little bit more control of the registration process…so I can close the registration lightbox. Am I missing something?? Shouldn’t this be possible.
I know I could store the additional data in custom members fields but I did this a long time ago and too much else ties into this other collection elsewhere now.
Here’s my code:
async function registerUser() {
$w('#errorMessage').collapse();
$w('#resetPassword').collapse();
let validationMessage = await fieldCheck();
if (validationMessage !== ''){
$w('#errorMessage').text = validationMessage;
$w('#errorMessage').expand();
} else {
let saveInfo = await submitInfo();
console.log("saveInfo");
console.log(saveInfo);
let saveReg = await submitReg();
console.log("saveReg");
console.log(saveReg);
}
}
async function submitInfo() {
var email = $w("#email").value;
var first = $w("#firstName").value;
var last = $w("#lastName").value;
var org = $w("#orgDropdown").value;
var role = $w("#role").value;
var newsletter = $w("#newsletter").checked;
let toInsert = {
"email":email,
"firstName":first,
"lastName":last,
"org":org,
"role":role,
"newsletter":newsletter
};
wixData.insert("IndividualsInfo", toInsert)
.then ((item) => {
return item
})
.catch((err) => {
wixWindow.lightbox.close();
wixWindow.openLightbox("Failed Reg");
})
}
async function submitReg() {
var email = $w("#email").value;
var password = $w("#password").value;
var first = $w("#firstName").value;
var last = $w("#lastName").value;
return authentication.register(email, password, {
contactInfo: {
'firstName': first,
'lastName': last
},
privacyStatus: "PUBLIC"
})
.then((registrationResult) => {
console.log("registrationResult");
console.log(registrationResult)
return registrationResult.status;
})
.catch((err2) => {
if (err2.includes("already exists in collection")) {
$w('#errorMessage').text = "This email address has already been used";
$w('#errorMessage').expand();
$w('#resetPassword').expand();;
} else {
wixWindow.lightbox.close();
wixWindow.openLightbox("Failed Reg");
}
})
}
Would appreciate help from anyone who’s made authentication.register work - I was using wixUsers.register until now, but its getting flaky so I am rewriting the blocks.
Thanks,
Simon.