Redirect logout to another page

Is it possible to redirect a member to home page (or any other page) when they logout from the members-only page?

Here’s what happened…

We have this members-only page. I clicked it.
I decided to logout.
Error 404 is showing.

We as Wix experts understand that it’s showing the error 404 because the link is supposed to be accessed by members-only. But other people don’t know that! They assumed something went wrong and they can’t logout.

So is there any way we can just show/pop up the “sign up/login” form again OR redirect them to homepage? Just to show that they have “successfully logged out”.

PS. I checked with Wix support already and they don’t have other solution aside from customizing the error 404 page.

I posted here to see if this can be resolved using Velo / code.

Thank you so much!

1 Like

You should be able to add an on logout function in the header of the site that redirects to a page using wixlocation.

Here are links on how to do so -
onLogout()
wixLocation.to()

2 Likes

I achieved this simply by resolving both at the same time.

Here’s the code:

$w("#menuAccountLogout").onClick(() => {
    Promise.all([wixUsers.logout(), wixLocation.to("/")])
});

This is a bit legacy so I’d use the new Wix Members logout method instead of Wix Users, but the idea is here.

3 Likes