Hello everyone, I’m new at wix coding and I was trying to find a way to hide the menu when the user loggs in the website. The idea is that, when the user is logged in I would show another information that only users are allowed to see with 3 pages inside.
My code is:
//code to hide or show menu when logged in or out.
//imports wix user database
import wixUsers from ‘wix-users’;
//let user = wixUsers.currentUser;
wixUsers.onLogin((user) => {
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49” let isLoggedIn = user.loggedIn; // true let userRole = user.role; // “Member”
$w(‘horizontalMenu1’).colapse();
});
//add a module named secureModule.jsw in backend part
// In backend file: secureModule.jsw
import wixUsers from ‘wix-users-backend’;
export function secureCheck() {
let currentUser = wixUsers.currentUser;
return currentUser.getEmail()
.then( (userEmail) => {
// here you test use email but you can test other element like role, name etc.
if(userEmail === “useremail@provider.com”) {
return “allowed”;
}
return “not-allowed”
} )
.catch((err) => {
return err;
} );
}
//in your page code
import {secureCheck} from ‘backend/secureModule’;
$w.onReady(function () {
//when page is loaded call HideMenuBar function
HideMenuBar();
});