If you want to keep a track of the number of seconds the user has been online for. Record the timestamp in UNIX when the user first logs in and then check for completion of 15 minutes (900 seconds) from that timestamp.
Put this on your Site Code tab.
import {session} from 'wix-storage';
import wixUsers from 'wix-users';
$w.onReady(function () {
setNow(); //set the initial time when the user lands on the page
setInterval( () => {
decisions(); //run a check every 3 seconds for the 15 minutes expiry
}, 3000);
});
function setNow() {
var d = Date.now();
var unix = Number(d) / 1000;
var time = Math.round(unix); //get the current time in seconds
let value = session.getItem("time");
if(!value && wixUsers.currentUser.loggedIn === true) {
session.setItem("time", time); //set the new timestamp only if one does not exist
}
}
function decisions() {
var d = Date.now();
var unix = Number(d) / 1000;
var time = Math.round(unix); //current timestamp
let value = session.getItem("time");
if(Number(value) + 900 > time) { //900 seconds is 15 minutes
//check if user is logged in and then logout
}
}