@ahmadnasriya Ok, i will give it a second try 
When i was inspecting your suggested code → i did not find…
$w.onReady(()=>{setInterval(sessionValidationFunc, interval_duration)})
Ok, will try to cut in peaces…
CHECK-POINT-1:
You trying to apply my code without understanding it well, my code doesn’t renew the token (via the interval), the interval only validates the stored token (from the session storage), to update the token, you need to call the renewToken( ) function from the appropriate event handlers, e.g. when the viewport is changed, when something is clicked or hovered.
Ok my code also do not renew the token, or to be more precise → my INTERVAL do not renew the token (or in my case → the online-time).
let myInterval = setInterval(validateSession,OnlineCheckClocking*1000);//(sec)
It’s just calling the → validateSession ← function every few (defined) seconds.
started from → MASTER-PAGE (onReady).
This is my → validateSession (running on EVENTS-PAGE)
export function validateSession() {console.log("Validation running....");
let onlineTime = Number(new Date())-DATA.expiration; console.log("Current-Online-Time: ", onlineTime);
DATA.onlineTime = onlineTime;
if (new Date().getTime()>=DATA.expiration) {
console.log({onlineTime: DATA.onlineTime, expiration: DATA.expiration, type:'success', action:'log-out', msg: 'Your online-time is expired ---> time for Log-Out!!!'});}
else {console.log({onlineTime: DATA.onlineTime, expiration: DATA.expiration, type:'success', action:'renew', msg: 'You are lucky, your time has not expired yet --> you can stay!'});}
}
Just checking for → setted EXPIRATION-TIME(DATE).
I do not stop any INTERVAL and START it again anymore. I use your technique just to validate if the setted Time-Stamp + given ONLINE-TIME (EXPIRATION-TIME) is already reached.
CHECK-POINT-1 → everything ok?
CHECK-POINT-2:
To renew the expiration-time (refill the online-time), i use a simple button-click…
One from master-page → test-button → “button1” —> “b1”
And one from normal-page → “btnAnalytics”.
$w('#btnAnalytics').onClick(()=>{set_newTimestamp();});
$w('#b1').onClick(()=>{set_newTimestamp();});
The token itself is useless, don’t give it that much of importance, it’s only used in the backend scenario to query the DB
Yes i do not take any attention on the token itself → for my case not important.
Imprtant for me is just the → TIME-STAMP / defined (ONLINE-TIME).
But exactly here i have my problem. Calling the → set_newTimestamp()-function
(what is nothing than a modified function of your example) which should RENEW the Time-STAMP → (it works well when firing this function from MASTER-PAGE), it does not work from the → normal-page.
The Time-Stamp do not renew at all. The INTERVAL continues his job during this.
This is my understanding.
It is not working perhaps → because i did cut of the SESSION?
I have used …
var DATA;
… directly on the EVENTS-PAGE instead.
Could this be the issue?
EDIT: CODE-COMPARISSON…
CODE by AHMAD: (Master-Page)
Note: You should only set the interval in the code in the masterPage.js file.
import { validateSession } from 'public/functions.js';const
interval_duration = 5 * 1000; // 5 sec
$w.onReady(() => {setInterval(sessionValidationFunc, interval_duration)})
vnCode: (Master-Page)
$w.onReady(()=> {set_newTimestamp();
let myInterval = setInterval(validateSession, OnlineCheckClocking*1000); //(sec)
$w('#b1').onClick(()=>{set_newTimestamp();});
})
Also did not found in your code → where do you set the first Time-Stamp ( renewToken() ), when user logs in ? For me, it seems → that i miss somethign in your provided code.