Hello everyone, I’m trying to create a login page and provide the ability to transfer data from one page to another. In the login page, it will check the database in order to see if the input email and password are the same as email and password stored in the database. After checking that, the input email that is equal to email stored in the database should be transferred into another page (main page). Please find below the code in the login page:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import {session} from ‘wix-storage’;
let userEmail;
let userPassword;
let user = wixUsers.currentUser;
$w.onReady( function () {
//TODO: write your page related code here…
$w(“#textErrors”).hide();
})
export function button1_click(event, $w) {
//TODO: write your page related code here…
let inEmail = $w(‘#input1’);
let inPassword = $w(‘#input2’);
let transEmail = inEmail;
wixData.query(“loginDB”).eq(“email”, inEmail).find().then((results) =>
{
let resultCount = results.totalCount;
if (resultCount)
{
userEmail = results.items[0].email;
userPassword = results.items[0].password;
if (inPassword===userPassword && inEmail===userEmail)
{
session.setItem(‘transEmail’, transEmail.value);//Keep in mind, ‘item’ must be a string.
wixLocation.to(/mainpage
);
} else {
$w(“#textErrors”).show();
$w(“#textErrors”).text = “Incorrect email or password.”;
}
} else {
$w(“#textErrors”).show();
$w(“#textErrors”).text = “Can’t find the user.”;
}
}). catch ((err) => {
let errorMsg = err;
});
return inEmail;
}
export function button2_click(event) {
//Add your code for this event here:
}
Here is the code in main page:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import {session} from ‘wix-storage’;
let filteredEmailtxt;
let filteredEmailvle;
let filteredEmail;
$w.onReady( function () {
//TODO: write your page related code here…
console.log(filteredEmail, “here is the email being sent to filter”);
console.log(“Dataset is now filtered”);
//$w(“#transEmail”).hide();
});
export function button3_click(event) {
//Add your code for this event here:
session.removeItem(“inEmail”);
session.clear();
}
export function trans_email(event, $w)
{
const transEmail = session.getItem(‘transEmail’); //Where result will be a string.
filteredEmail = transEmail;
}
However, the outcome is:
undefined here is the email being sent to filter
So what did I do wrong here?
#transferdata
#transferringdatabetweenpages