Bruno, i found the solution !
Now a question to you.
Would you prefer still to work with JWT (JSON Web Token), instead of an internal working code-solution on your own site (where you also are able to handle your logging-out function from everywhere of your page? Why?
I had hoped Mr. Zaytsev might also have contributed the one or the other idea.
And an unresolved question would still be… → Why i can’t use a PUBLIC-VARIABLE on the PUBLIC page as i was expecting it in my first trys ?
var DATA
@Bruno
Perhaps, even this also would now work → when doing it trough wix-storage, instead of using an global variable on the public-js-page.
I would guess that myInterval is not global scope. So you are creating two distincts variables that are holding setInterval(). Try assigning a random UUID to check this theory.
When you try to access something in a code file, the code file gets stored into the memory (the device RAM) and gets assigned to the operation you’re trying to perform, so …
Let’s assume you have 3 pages, A, B, and you want to get something from page A, and then update it.
// Page A
const config = {
id: 'String A',
}
export function getConfig() {
return config;
}
export function update_id(id) {
config.id = id;
return config;
}
// Page B
import a from 'public/a.js';
// #1: get the initial value of the config.
const config = await a.getConfig(); // returns { id: 'String A' }
// #2: Update the config, and return the updated value immediately
await a.update_id('String B'); // returns { id: 'String B' }
// #3: get the config again;
await a.getConfig(); // returns { id: 'String A' }
What do you notice? What’s going on?
Each attempt to read the code file will read its original state, any changes you make with a function call only affect the code file in the RAM, not the actual file, the original file remains intact.
@russian-dima I used JWT because is some kind of standard in website security (arguably) and most websites don’t kick you of the website unless you try to interact with it, the last page logged in is the page you still can see, but not interact. I read once somewhere that setInterval() increases the amount of resources used in your application, so I tend to avoid using it.
And although you have to use a NPM Package, it is so widely used and supported (even Velo) that I see no problem using it. I created a custom login page that uses it and it works just fine. The session has a 24h expiration date, after that, if you interact with the site, it redirects you to the login page. And everything is done in the backend.
@ahmadnasriya
Ok, as i understood → i simply can’t store data in a variable on public-page.
Now i also understand why i could not manage the ONLINE-TIMER, which was also placed on public-page → but now i got the solution! → Timer WORKING !!!
What i am talking about can be seen here… (mxOnline-Time). Wrong placement:sweat_smile:
import {session} from'wix-storage';
//------User-Interface-------------------------
var maxOnlineTime=0.5; //0,5-Minutes --> 30-secs! --> Logging-Out ater 30-secs
//------User-Interface-------------------------
//var DATA; <<<<<----------THAT WAS THE PROBLEM ! ! !