Hi, I'm trying to solve this for a few days now. What I need is to read the user member role (Ambassador), created in the roles section of the Dashboard and use a button to send the user to a specific location. When the role is different, the button remains the same but the location changes.
So far I'm not getting a single result! HELP!!!
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
let url = wixLocation.url;
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
// this is where the button gets displayed if the user is a member
$w.onReady( () => { if(wixUsers.currentUser.loggedIn) { $w("#dashboardButton").label = "My Dashboard"; $w("#dashboardButton").show(); } else { $w("#dashboardButton").hide(); } } ); // This should be getting the actual member role (Ambassador)
user.getRoles() .then( (roles) => { let firstRole = roles[0]; let roleName = firstRole.name; // "Role Name" let roleDescription = firstRole.description; // "Role Description" } ); // This is where I get lost!!
export function dashboardButton_click(event) {
const currentUser = wixUsers.currentUser;
if (currentUser.roleName === 'Ambassador'){
$w('#button28').show();
} else{
console.log();
}
}
I am so lost, how did you finally fix it?
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
Even tried to clean it but even when the user is an "influencer" it shows me the button for ambassador.
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(); } });
You need to make sure that you go through your code and check that your code has matching pairs of open and closed curly brackets ( '{' and '}') as well as matching pairs of parentheses ('(' and ')').
See here for more info from an old post that explains it to you.
https://www.wix.com/corvid/forum/community-discussion/parsing-error-unexpected-token
https://www.wix.com/corvid/forum/community-discussion/showing-certain-data-in-a-collection-to-specific-members-only