To display login / logout buttons based on user current login to wix website, we must write the code on masterPage.js. The below example uses authentication from wix-members module to check if user is logged in.
The first IF condition checks if user is already logged into the website then just show the logout button.
The authentication.onLogin function is triggered when users logs into the website form any page
Note: by default the logout button is hidden on the frontend
import { authentication } from 'wix-members';
$w.onReady(function () {
const loggedIn = authentication.loggedIn();
if (loggedIn) {
console.log('Logged in, showing the logout button');
$w('#logout').show();
}
authentication.onLogin(() => {
console.log('Logged in, showing the logout button');
$w('#logout').show();
});
});
Enjoy !! 🚀🚀🚀