Hey guys!
If you’re trying to create a custom log out button for your wix-members website simply add this code to the page you need (or in your header/footer and it’ll work a treat!
Happy Coding!
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
$w.onReady(() => {
$w("#button208").onClick(logoutAndRedirect);
});
function logoutAndRedirect(event) {
Promise.all([wixLocation.to('https://www.stockshub.uk/'), wixUsers.logout()]);
}
And here’s how each line of code works:
// Import the ‘wix-location’ module to be able to navigate to a different URL
import wixLocation from ‘wix-location’;
// Import the ‘wix-users’ module to be able to log out the current user
import wixUsers from ‘wix-users’;
// Set an event listener to run the ‘logoutAndRedirect’ function when the button with ID ‘button208’ is clicked
$w.onReady(() => {
$w(“#YourButtonIDHere”).onClick(logoutAndRedirect);
});
// Define the ‘logoutAndRedirect’ function, which logs out the current user and redirects to the desired URL
function logoutAndRedirect(event) {
// Use Promise.all() to wait for both navigation and logout to complete
Promise.all([wixLocation.to(‘YourWebsiteURLHere’), wixUsers.logout()]);
}