You have a mistake in your code, the else{} part is not in place.
It should be:
if (roles.some(r => r.name === "Ambassador")) {
$w("#dashboardButton").show();
} else {
$w("#dashboardButton").hide();
}
You have a mistake in your code, the else{} part is not in place.
It should be:
if (roles.some(r => r.name === "Ambassador")) {
$w("#dashboardButton").show();
} else {
$w("#dashboardButton").hide();
}
And ignore the duplication bug.
@yisrael-wix , don’t put the tables back, leave them down on the office floor.
@jonatandor35 Thanks J.D I corrected it again but, like I said, the button shows independent of the member role. Is there a way I can check which role is reading? This is the code as it is now:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
let user = wixUsers.currentUser;
let url = wixLocation.url;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
user.getRoles()
.then( (roles) => {
if (roles.some(r => r.name === “Ambassador”)) {
$w(“#dashboardButton”).show();
} else {
$w(“#dashboardButton”).hide();
}
})
}
});
@jonatandor35 Haha thats the new running gag here
I just managed!!! Thanks @J. D. I really appreciate the help! If you wanna collect that bottle of wine, please send me an email to andres@thebsq.com
You’re welcome.
But let me say that this code doesn’t cover the situation where the user logs in from this page.
To do that, you’ll have to to create a serachRole function, and to run it on page ready as well as on use log in.
@jonatandor35 Uhhhm ok… Would you be kind to point me in the right direction to do that? I’m not sure where to start with it.
I am so lost, how did you finally fix it?