Logout() redirection issue

I am setting up a members area and have created my own login page, which works very well. However, when I perform a logout() via code, following the log out there is a redirection to the Wix login page. How do I get it to either 1) redirect to my login page, or 2) do no redirection at all so that I can use a wixLocation.to () to go where I want.

1 Like

post your logout code

export function buttonLogout_click(event) {
//Handle logout as the result of a LOGOUT button selection
wixUsers.logout();
wixLocation.to(ā€œ/artistloginā€);
}

ā€œ/artistloginā€ is my login page, but the redirection never goes there because the Wix login page appears.

Try this article: https://support.totallycodable.com/en/article/log-out-button-with-redirect

It seems like you need your wixLocation BEFORE the wixUsers.logout

Hi Bill, can you let us know if @brettfranklin2 's solution works. Interested to know if it does, and how.

As suggested, I reversed the logout() and redirection lines in the code, but it did not solve the problem. However, I also learned more about what the real issue is, and it is not with the logout() function at all.

Try the following experiment and you will see the issue:

  1. Access my website at: https://www.intowngallery.com
    Scroll down to the footer and click on the darker circle on the right side. That takes you to my custom login page. You can’t log in, but that does not matter. (Incidentally, this interface is temporary to keep the function out of the purview of the general user until I finish it.)

  2. Now access the following URL: https://www.intowngallery.com/Directory/Profile
    This is a page in the members area that you don’t have permission to access since you are not logged in.
    Note that it brings up the Wix login page!

How do I control/prevent this?

Cheers,
Bill

It also seems like there should be no semicolon after wixLocation.

In a partial answer to my own issue, I decided to write a router to redirect requests for my member pages to my custom login page. However, I have encountered problems doing this, which I will make the topic of a new thread (here: https://www.wix.com/code/home/forum/community-discussion/router-issue-control-redirection-with-login-status )

What I did because I am also having trouble with this is that I created a new page called logout. The button for logout redirects users there while logging them out. When users are on the page then they become automatically logged out.

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 and nobody minds that I’m posting it on several forum queries like this. Cheers.