30 minutes auto logout users after login

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);
        }
    }

 
}

For 1 minute timeoff, the coding could run smoothly.

For 30 minute time-off, the coding did not run. System just redirect users to the homepage, but users was still login.
Before the console refresh for 30 minute.

After 30 minutes, the console is refreshed. However, the user was still logged in.

With references to the following page, logout users when browser is closed.

I changed to use promise all, logout and clear the session after 30 minutes.

After 30 minutes, then logout is failed, but session is cleared.

With the checking if no session, then auto logout.
Finally, the logout users after 30 minutes could be worked.

import { authentication } from 'wix-members';

import wixLocation from 'wix-location';
import { session } from 'wix-storage';
$w.onReady(async function () {
    const timeOut = 60000*30;

     if (authentication.loggedIn() && 
     !session.getItem('isLoggedInThisSession')) { 
     //wixLocation.to('/');
     await authentication.logout() ;
     wixLocation.to('/'); 
    
 } 
  
    console.log("Reloading Master Page, Still logged in??", authentication.loggedIn());
    const loggedIn = authentication.loggedIn();
    if (loggedIn) {
      /*
        for (var i =0; i <=timeOut; i++ ){
           await delay (1500);
           console.log (" i " + i);
        }
        */
          setTimeout(() => {
           console.log("time to logout " + new Date());
      //  wixLocation.to("/");
       // authentication.logout();
         Promise.all( [ wixLocation.to('/'), authentication.logout(),session.clear() ] );
         }, timeOut);
          console.log ("logged out at "+ new Date() );
           authentication.onLogout(() => {
            console.log('Member logged out onLogout at ' + new Date());
            session.clear();
            wixLocation.to("/");
           });