When on a members page, if I try to log out it breaks the page.

I’m using a custom lightbox to have customers log in and out of our site. If a customer is logged in and on one of the member account pages and tries to log out it shoots them back to the login lightbox which then breaks and they cant close our of the light box. It’s refreshing the account page that they are on with no way around.
My ideal outcome would be to have the logout button redirect to the homepage, not the lightbox. How can I achieve this?

Hi,
Can you please share a link to your site so we can inspect?
Roi.

Hi All,

I’m fairly new to Wix and notice that answers can be hard to find for certain issues.
With the help of the good folk on here and much thought, I’ve been able to figure out most things Corvid.

This issue seems to come up a lot so I thought I’d throw my 2 cents in for a simple solution and furthermore, a simple helpful feature.

wixLocation.to(‘/’)
wixUsers.logout().setTimout(500);

The code above seems to redirects the user then log them out but in function and because of Asynchronous code operation, the logout ends up occurring first.

By setting the timeout (half a second here), the logout function execution is delayed. This can be increased or reduced.

One simple but handy function is a dropdown with redirection to various pages or other functions (use an if statement to assess the selection for other functions, and include a logout.

Here is the example:

import wixLocation from ‘wix-location’;

$w.onReady(function (event) {

InitiateUserMenu()          

});

export function InitiateUserMenu(){ //CALLED FROM THE ONREADY() ABOVE.

let MenuOptions = [ //SET THE ITEMS IN THE DROPDOWN MENU

    {"label": "MenuName1", "value": "RedirectToAddress1"}, 
    {"label": "MenuName2", "value": "RedirectToAddress2"}, 
    {"label": "Logout", "value": '/'} 

]; 
$w('#UserDropMenu').placeholder = "Placeholder";   //PLACEHOLDER CAN BE THE USER'S NAME 

$w('#UserDropMenu').options = MenuOptions;         //LOAD THE MENUOPTIONS VARIABLE IN 

$w("#UserDropMenu").onChange( (event, $w) => {    //WHEN ITEM IS SELECTED DO THE FOLLOWING 

if($w("#UserDropMenu").value === '/'){       //IF VALUE OF SELECTED IS THAT OF HOME, LOG US OUT 

        wixLocation.to($w("#UserDropMenu").value)    //REDIRECT TO HOME 
        wixUsers.logout().setTimout(500);                    //LOGOUT USER WITH A HALF SECOND DELAY    

    }else{ 

        wixLocation.to($w("#UserDropMenu").value);   //REDIRECT TO THE VALUE OF SELECTED ITEM 

    } 

}); 

}

The code above only requires a simple dropdown named UserDropMenu to work.

I hope people find this info and code useful. Cheers.