This should get you started:
import { authentication, currentMember } from 'wix-members-frontend';
$w.onReady(async function () {
let isLoggedIn = authentication.loggedIn();
$w("#button1").hide();
if (isLoggedIn) {
let member = await currentMember.getRoles()
if (member.some(r => r.title === "Admin")) {
$w("#button1").show();
} else {
$w("#button1").hide();
}
}
})
Here’s what it does:
- Imports 2 API’s. One for check current member details, and one for authenticating the member.
- When the page is ready, create a variable to see if the member is logged in.
- Set the button as hidden by default.
- If the member is logged in, run the code in between the
{}
- If the member is logged in, check to get their roles
- Check all the members roles and see if one of them is “Admin”. If it is, show the button. If it’s not, hide the button.
Let me know if you have any questions