Redirect Member After Logout... I'm stuck!

I created a button that allows our members to click it and sign out of their account. I used the following code. But what more do I add that would redirect the member to a certain local page afterwards.

import { authentication } from ‘wix-members’

$w ( '#logout' ). onClick (() => { 
    authentication . logout (); 
});

If the code you have works, you are probably looking to add this:

wixLocation.to("/page-slug");

So, you would change - /page-slug to the slug of the page you want to redirect to. It would look something like this:

import{authentication}from 'wix-members'      

$w('#logout').onClick(()=>{
	authentication.logout();
	wixLocation.to("/page-slug");
});

Another way to handle it is to catch the onLogout event in the masterPage.js file. This would have the advantage that it would also redirect the users when they logout via the menu option. Adding this code to the masterPage.js will do the trick.

import wixLocation from ‘wix-location’;
import {authentication} from ‘wix-members’;

$w.onReady(function () {

// This event handler is fired when the member logs out of the app.
// Redirect the member back to the home page
authentication.onLogout(() => {
console.log(‘Member logged out.’);
wixLocation.to(“/”);
});

});

This is the answer you are looking for. I wrote my answer in a bit of a rush and forgot one or two things.

@noahlovell thank you!!