vatnaz
1
Hello all. I’m trying to make a container appear if a site member has the label ‘Student’. Here’s my code. What am I doing wrong? Many thanks!
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
let user = wixUsers . currentUser ;
user . getRoles ()
. then ( ( roles ) => {
let userRole = user . role ;
if ( roles . some ( r => { return ( r . name === “Student” )}) === true ) { $w ( “#membersoptions” ). show ();}
});
})
amandam
2
Hello, I see a few issues here.
First, you want to use wix members . The users API is deprecated.
Second to see what roles the currently logged in member has, you will want to use getRoles
I also see no reason in the code for the wix-data import. If you are not using this elsewhere, you can remove it.
And finally, since you are using traditional promise chains (.then) instead of async/await, there is no reason to put async in your onReady
Once you know you are getting the current members roles back successfully, then you can implement the hide/show.