I’m trying to make a login form by filtering the database with the user email and password. I’m not a programmer so I’m trying my best. In the preview mode the code runs with no problem but when I make it live the code won’t work. I don’t know what’s the problem. Please help me find the solution.
Here is my piece of code.
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady(function () {
//TODO: write your page related code here…
});
let validationMessage = ’ ';
function usersLogin()
{
let userId;
let userEmail;
let userPassword;
wixData.query("Employee")
.eq('email', $w('#inputEmail').value)
.eq('password', $w('#inputPassword').value)
.find()
.then((results) => {
if (results.items.length !== 0) {
wixLocation.to("/login-employee");
//wixLocation.to("http://www.google.com/");
$w('#validationMessages').collapse();
//update buttons accordingly
$w('#button9').label = 'Logout';
}
else
{
validationMessage += 'Invalid email or password\n ';
$w('#validationMessages').text = validationMessage;
$w('#validationMessages').expand();
}
} )
.catch( (err) => {
console.log(err);
} )
}
export function buttonLogin_click(event, $w) {
//Add your code for this event here:
validationMessage = ’ ‘;
$w(’#validationMessages’).text = validationMessage;
$w(‘#validationMessages’).collapse();
if (!($w('#inputEmail').valid && $w('#inputPassword').valid))
{
if (!$w('#inputEmail').valid)
validationMessage += 'Please enter your email\n';
if (!$w('#inputPassword').valid)
validationMessage += 'Please enter your password\n';
$w('#validationMessages').text = validationMessage;
$w('#validationMessages').expand();
}
else
{
usersLogin();
}
}
Thanks a lot guys.