Good morning, I have the following problem I hope you can help me one more time. First of all I explain why the way I decided to do it this way, I have my site in which it has a login page since I do not need a registration since the users will be directly in the database entered manually in a dataset, the login was built with the following elements and the following code
import wixData from "wix-data"
import wixLocation from "wix-location"
import wixWindow from 'wix-window';
$w.onReady(() => {
$w("#button1").onClick(async () => {
let email = $w("#email").value
let contrasena = $w("#contrasena").value
await checkLogin(email, contrasena)
})
})
async function checkLogin(email, contrasena) {
const query = await wixData
.query("logingers")
.eq("title", email)
.eq("contrasena", contrasena)
.find()
if (query.items.length > 0) {
wixLocation.to("/principal")
} else {
$w( "#text8" ).show()
// here I would like my window to appear with the error message
wixWindow.openLightbox ( 'mensaje error' )
// console.error("Email/Contrasena wrong!")
}
}
The pages have a horizontal menu in which the “events” button directs the login and this in turn directs to a “main” page that cannot be accessed from the menu without going through the login.
The big problem I have is that once the user logs in to see the content of the “main” page and continues browsing the site and wants to see the “main” page again by clicking on the “events” button of the The menu again directs you to the login without respecting that you had previously logged in, as shown in the video
Previously they had helped me to implement a kind of timer that would recognize the session for a certain time, once the indicated session time expired again, the login would appear, but as you can see, it does not work, it still does not recognize the session, I show code
import wixStorage from 'wix-storage';
import wixLocation from 'wix-location';
import wixData from 'wix-data';
import wixWindow from 'wix-window';
var onlineState
$w.onReady(() => {
setInterval(logOut, (5*1000*60)); // --> LOGOUT every 5min
$w("#button1").onClick(async () => {
//getting online-status...
onlineState = wixStorage.session.getItem("onlineState");
if(onlineState === "true") {
wixLocation.to("/principal")
}
else {
let email = $w("#email").value
let contrasena = $w("#contrasena").value
await checkLogin(email, contrasena)
}
})
})
function logOut() {onlineState === "false";
//setting online-status...
wixStorage.session.setItem("onlineState", "false");
}
async function checkLogin(email, contrasena) {
wixData.query("logingers")
.eq("title", email)
.eq("contrasena", contrasena)
.find()
.then((res)=>{
if (res.items.length > 0) {//setting online-status...
wixStorage.session.setItem("onlineState", "true");
wixLocation.to("/principal")
} else {
wixWindow.openLightbox('loginwarn');
//console.error("Email/Contrasena wrong!")
}
});
}
How can I do to achieve this? Could it be the button on my menu? Could you please help me?