I’m have some trouble when users try to log out from their profile page of any other members restricted pages this 403 pages appears?
—>
I’m trying to setup an wixLocation.to so when they click on the logout button on any restricted page they will be redirected to the web page home screen… That’s the plan, but it doesn’t seem to be working. Can someone take a look and see what I’m going wrong.
export function loginButton_onClick() {
// User is logged in
if (wixUsers.currentUser.loggedIn) {
// Log the user out
wixUsers.logout()
.then(() => {
// Update buttons accordingly
wixLocation.to("http://arthosmaciel.wixsite.com/wixacademy-demo");
$w("#loginButton").label = "Login";
$w("#profileButton").hide();
});
}
Also it’s the same code on creating a members support page from wix… Could the root of the problem be because it’s a dynamic page?
Old post, but reviving in case anyone else runs into this issue.
SOLUTION: I made the loginButton function async and added an await before the WixLocation. This redirects the user to the home page, first, then logs them out. If you don’t do this it will log them out and keep them on the same page.
export async function loginButton_click(event, $w) {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
await wixLocation.to('/');
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#loginButton").label = "Login";
$w("#profileButton").collapse();
} );
}
$w.onReady(() => {
// We check if the user is logged in from another session, send then to the home page, and log them out
if (wixUsers.currentUser.loggedIn &&
!session.getItem('isLoggedInThisSession')) {
//wixLocation.to('/');
return wixUsers.logout().then(() => {
wixLocation.to('/');
});
}if (wixUsers.currentUser.loggedIn) {
$w("#button8").label = "Logout";
$w("#button9").show();
$w("#button14").show();
}else {
$w("#button8").label = "Login";
$w("#button9").hide();
$w("#button14").hide();
}
});
My buttons are on the site (displayed in the header); so perhaps that makes a difference.