Hi there,
I have been trying all the codes that I can find here but I haven’t get this to work,
I need to hide and show buttons based on the user current user role
This is the last code that I used, still does not work, on page load, I want some buttons to be visible and some hidden based on the member.
import wixUsers from ‘wix-users’;
$w.onReady(function(){
const currentUser = wixUsers.currentUser;
if (currentUser.loggedIn && currentUser.role === ‘Admin’){
$w(‘#button1’).show();
} else {
$w('#button2).hide();
}
});
Do we have to leave the button proprieties blank of choose the default?
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
$w.onReady(function(){
$w("#button1").hide();
if(user.loggedIn){
user.getRoles()
.then( (roles) => {
if (roles.some(r => r.name === "Admin")){
$w("#button1").show();
}
});
}
})
Assuming that the things that only Admin’s may see/click may grow, take great answer above to where you anticipate that with adminShowArray[]
import wixUsers from ‘wix-users’ ;
const user = wixUsers.currentUser;
const adminShowArray = [ “#develLink”,“#btnGoToMembers” ];
$w.onReady( function () {
if (user.loggedIn){
user.getRoles()
.then( (roles) => {
if (roles.some(r => r.name === “Admin” )){
for ( var i = 0 ; i < adminShowArray.length; i++) {
$w(adminShowArray[i]).show();
}
}
});
}
});
Kindly elaborate on this :
if (roles.some(r => r.name === “Admin”)){
I wanna understand what this statement do?
finds out if somebody has a role
Hi there, trying to get this to work but for site members (signed up users) rather than admin?
We want the button to be a clickable download link but only for signed up members.