I am trying to create a custom login page where you enter the email > continue > choose password
Is there any way to check if the email is already in use before continuing?
Thank you for your time
Something like this…
import wixUsers from ‘wix-users’;
import wixLocation from “wix-location”;
import wixData from “wix-data”;
$w.onReady( function () {
$w('#SignupRegisterButton').onClick(() => {
//format email into all lowercase so that every email input into the memberDatabase is in the same format
let unformattedUserEmail = $w(“#SignupEmailInput”).value;
let formattedUserEmail = (unformattedUserEmail).toLowerCase();
console.log(formattedUserEmail);
//query the user database to ensure the new user email has not been previously been used to register
wixData.query("memberDatabase")
.eq("userEmail", (formattedUserEmail))
.limit(1)
.find()
.then((results) => {
let emailPreviouslyRegistered = results.totalCount; // number of times email appears in the user database should be 0
console.log(emailPreviouslyRegistered);
if (emailPreviouslyRegistered === 0)
{
// pass name and email to seperate DB as well as the CRM so as user names can be read on live site
//passing to database
$w("#memberDataset"). **new** ()
.then(() => {
$w('#memberDataset').setFieldValue('firstName', $w('#SignupFirstNameInput').value);
$w('#memberDataset').setFieldValue('lastName', $w('#SignupLastNameInput').value);
$w('#memberDataset').setFieldValue('userEmail', (formattedUserEmail));
$w('#memberDataset').save();
})
//passing to CRM
wixUsers.register((formattedUserEmail), $w('#SignupPasswordInput').value, {
“contactInfo”: {
“firstName”: $w(‘#SignupFirstNameInput’).value,
“lastName”: $w(‘#SignupLastNameInput’).value,
“dob”: $w(‘#SignupDOBDatePicker’).value,
}
})
.then(() => {
console.log('user registered successfully');
wixLocation.to('https://yourhomepage.com');
})
} **else**
console.log("User not registered");
})
})
})
I tried the code but I have a problem with the query. Every time it returns 0 and I cannot figure out why. This is my first time working with databases. I created one called Users (Read by Anyone) with field keys (title, email) and if I use the sample code below I always get 0.
Edit: I observed that in preview mode works fine but it doesn’t work on the actual site.
import wixUsers from ‘wix-users’;
import wixLocation from “wix-location”;
import wixData from “wix-data”;
$w.onReady( function () {
$w('#text29').hide();
$w('#register').onClick(() => {
//format email into all lowercase so that every email input into the memberDatabase is in the same format
let unformattedUserEmail = $w(“#email”).value;
let formattedUserEmail = (unformattedUserEmail).toLowerCase();
//query the user database to ensure the new user email has not been previously been used to register
wixData.query("Users")
.eq("email", (formattedUserEmail))
.find()
.then((results) => {
let emailPreviouslyRegistered = results.totalCount; // number of times email appears in the user database should be 0
if (emailPreviouslyRegistered === 0) {
$w('#text29').text = "Continue to register";
$w('#text29').show();
} **else** {
$w('#text29').text = "The email is already used";
$w('#text29').show();
}
})
})
})
up
Sync the DB to Live