Why? Why am I just changing the time-out from 60000 * 3 to 60000* 30, the coding doesn’t work anymore.
If the checkTimeAgain =60000*3, the code is worked, and after about 3 minutes, the system would automatically log out a signed user.
However, I changed to using 60000 * 30, then no matter how long it takes, the screen only changes to the default homepage, but the logged users, still log in.
Here is the coding at the masterPage.js
import {authentication} from 'wix-members';
import wixLocation from 'wix-location';
import { generateLoginToken, getLoginToken } from 'backend/login.jsw';
$w.onReady( async function () {
// Write your code here
const checkTimeAgain = 60000 * 30; //This line represents the time in milliseconds. 60000 milliseconds equals to 1 minute.
setTimeout(() => {
const today1 = new Date();
const hour1 = today1.getHours();
const minute1= today1.getMinutes();
console.log("Time checked. The new current hour1 is " + hour1 +":"+ minute1 ) ;
console.log ("It is time up");
checkAgain(); //This line triggers the code to check for the time again.
}, checkTimeAgain);
});
function checkAgain() {
const today = new Date();
const hour = today.getHours();
const minute= today.getMinutes();
console.log("Time checked again. The new current hour is " + hour +":"+ minute ) ;
const loggedIn = authentication.loggedIn();
if (loggedIn) {
console.log('Logged in, showing the logout button');
authentication.logout();
wixLocation.to("/");
} else {
console.log('session already expired');
try {
authentication.logout();
}
catch (err ) {
console.log (err.message);
}
}
}