Wix Users Logout Problem

Starting off with the code itself:

function PageTimeOut() {
    setTimeout(() => {
        setTimeout(() => {wixUsers.logout();},800);
        wixLocation.to("/");}, 240000);
}

I’m trying to timeout a page and after the page times out the member is automatically logged out and redirected to the home page or some other page. However, after getting out and redirecting to the home page the log in page returns again after which the user can again log back in to the same page that timed out. What I want is that the page should time out, the user logged out and redirected to another page and stop there. Any help or suggestions? I’m attaching a gif image. Notice how the redirect again goes back after logging out; That should not happen, it should stay on the home page after redirecting and logging out.

Hi Vipul,

Did you try to navigate to home first and only then logout the user? From the gif it looks that re-login brings the user to the last page he/she visited. Or maybe you managed to solve the problem yourself? It would be great to see your solution :slight_smile:

Marius

1 Like

Hi Marius,

Yeps, I tried what you said but that doesn’t work either probably because after all the logout() runs and then the control gets back to the previous page. Never mind, I figured a way out and here’s the code. What I did is that I passed a string from that page while redirecting and handled that query on the home page.
Here’s the home page code:

export function use_myFunction(request) {

 let query = request.query; // {"q": "value"}

}
$w.onReady(function () {
    waitForLoading();
 if (wixLocation.query.logout === 'true') {
        wixUsers.logout();
    }

});
export function button6_onClick(event) {
    $w('#preloader').show();
    waitForLoading();
}

And here’s the code that sits on the page which redirects users to the home page.

$w.onReady(function () { //$w.onReady(() => 
{ 
$w('#button2').hide(); 
$w("#button1").disable(); //Disable the show QR button initially. 
$w('#button2').disable(); //Disable the Complete Payment initially. const today = new Date(); // Gets today's date 
$w("#datePicker1").onChange( (event, $w) => { let newValue = event.target.value; dateStr = newValue.toDateString(); // "new value" if (dateStr === (today.toDateString())) //check if date retrieved via datepicker object is a valid date and matches today's date. 
{ $w("#text102").hide(); //hide error message val=1; } else { $w("#text102").show(); //show error message 
$w("#button1").disable(); $w('#button2').disable(); //deactivate show QR button val=0; } } ); 
setTimeout(() => {wixLocation.to("/?logout=true"); }, 180000); } );

P.S. Ignore the comments and other irrelevant code.

Best,
Vipul.