Help! Error on accessing roles

Question:
I need help getting the role information form a logged in member.

Product:
Wix Editor

What are you trying to achieve:
I need to detect different roles (“Student”, “Senior Staff”, etc.) so I can use the information in a if statement to Controll what sections of a dynamic page will be displayed.

What have you already tried:
I have searched and tried different code. this seems like it should work but it returns the error: “Error: t.text is not a function. (In ‘t.text()’, ‘t.text’ is undefined)” If I remove the code the error goes away.

Code:
//Notes:
// I have this import code at the top // import wixUsers from ‘wix-users’; //
// code is Inside the // $w.onReady(function () )}; //

//Check to see if the member has Student role access
let isStudent = false;

if (wixUsers.currentUser.loggedIn) {
	// Get the user's member roles
		wixUsers.currentUser.getRoles()
  	 	.then((roles) => {
      		 // Check if the user has any of the Student role
       		if (roles.some(r => r.name === "Student")) {
        		isStudent = true;
       		} else {
        		isStudent = false;
       		}
   		});
}

if(isStudent) {
		$w('#buttonStudent').show();
} else {
	$w('#buttonStudent').hide();
}

First of all, you should switch to new members APIs. (Not required but recommended)

I can’t see the text section in your code. Did you share all of your page code? If not, can you share all the page code, you have problem with.

though I have some minor coding experience I have just started trying to implement things with WIX. I was unaware of the new members APIs. I will look those up shortly.

The code is a bit Frankensitned to gather right now and not optimized as I am working on figuring out how to so things. Here is the full body of code:

// Velo API Reference: Introduction - Velo API Reference - Wix.com

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {

//---------------------------------------------------------------
//
//                 Get role restrictions Authorizaiotn
//
//---------------------------------------------------------------
let isBlackBelt = false;

//Check to see if the member has Student role access
let isStudent = false;

if (wixUsers.currentUser.loggedIn) {
	// Get the user's member roles
	wixUsers.currentUser.getRoles()
   	.then((roles) => {
        // Check if the user has any of the Student role
       		if (roles.some(r => r.name === "Student")) {
        		isStudent = true;
       		} else {
        		isStudent = false;
       		}
   	});
}

if(isStudent) {
	$w('#buttonStudent').show();
} else {
	$w('#buttonStudent').hide();
}

if(isBlackBelt) {
	$w('#buttonBlack').show();
} else {
    $w('#buttonBlack').hide();
}
		



//---------------------------------------------------------------
//
//                 Refresh the page when the user logs in
//
//---------------------------------------------------------------

wixUsers.onLogin(function(user) {
wixLocation.to(wixLocation.url);
});

$w("#dynamicDataset").onReady(()=>{
	let currentItem = $w("#dynamicDataset").getCurrentItem();

//---------------------------------------------------------------
//
//                 Item Name Section
//
//---------------------------------------------------------------




//Item Seciton Name
	if(currentItem.bItemSectionName===true){
		$w("#sectionItemSectionName").show();
		$w("#sectionItemSectionName").expand();
	} else {
		$w("#sectionItemSectionName").hide();
		$w("#sectionItemSectionName").collapse();
	}


// Item Informaiotn
	if(currentItem.bItemInformation===true){
		$w("#sectionItemInformation").show();
		$w("#sectionItemInformation").expand();
	} else {
		$w("#sectionItemInformation").hide();
		$w("#sectionItemInformation").collapse();
	}


//---------------------------------------------------------------
//
//             Video Header Section
//
//---------------------------------------------------------------


// Video Header
	if(currentItem.bVideoSection===true){
		$w("#sectionVideoHeader").show();
		$w("#sectionVideoHeader").expand();
	} else {
		$w("#sectionVideoHeader").hide();
		$w("#sectionVideoHeader").collapse();
	}


//---------------------------------------------------------------
//
//             Video Front View Text Section
//
//---------------------------------------------------------------


// Front View Text
	if(currentItem.bVideoSection===true){
		if(currentItem.bVideoFrontView===true){
			if(currentItem.bDemonstrationFvm===true){
				$w("#sectionFrontViewText").hide();
				$w("#sectionFrontViewText").collapse();
			} else {
				$w("#sectionFrontViewText").show();
				$w("#sectionFrontViewText").expand();
			}
		} else {
			$w("#sectionFrontViewText").hide();
			$w("#sectionFrontViewText").collapse();
		}
// Front View Text Mirror
		if(currentItem.bVideoFrontView===true){
			if(currentItem.bDemonstrationFvm===true){
				$w("#sectionFrontViewTextMirrored").show();
				$w("#sectionFrontViewTextMirrored").expand();
			} else {
				$w("#sectionFrontViewTextMirrored").hide();
				$w("#sectionFrontViewTextMirrored").collapse();
			}
		} else {
			$w("#sectionFrontViewTextMirrored").hide();
			$w("#sectionFrontViewTextMirrored").collapse();
		}
//No Front View Text
	} else {
		$w("#sectionFrontViewText").hide();
		$w("#sectionFrontViewText").collapse();
		$w("#sectionFrontViewTextMirrored").hide();
		$w("#sectionFrontViewTextMirrored").collapse();
	}

//---------------------------------------------------------------
//
//             Video Front View Youtube vs Wix Section
//
//---------------------------------------------------------------


// FRONT VIEW: Test -> Video Seciton -> Youtube or Wix Video
	if(currentItem.bVideoSection===true && (currentItem.bDemonstrationFvVideoYt===true || currentItem.bDemonstrationFvVideoWv===true)){
		// FFRONT VIEW: Check to see if STUDENT restrected
		if (currentItem.bDemonstrationFvVideobStudentRole===true){
			$w("#sectionFrontViewStudentsOnly").hide();
    		$w("#sectionFrontViewStudentsOnly").collapse();
			$w("#sectionFrontViewBlackBeltsOnly").hide();
       		$w("#sectionFrontViewBlackBeltsOnly").collapse();
			$w("#sectionFrontViewVideoYouTube").show();
       		$w("#sectionFrontViewVideoYouTube").expand();
			$w("#sectionFrontViewVideoWixVideo").hide();
       		$w("#sectionFrontViewVideoWixVideo").collapse();
		} else {
			$w("#sectionFrontViewStudentsOnly").show();
    		$w("#sectionFrontViewStudentsOnly").expand();
			$w("#sectionFrontViewBlackBeltsOnly").hide();
       		$w("#sectionFrontViewBlackBeltsOnly").collapse();
			$w("#sectionFrontViewVideoYouTube").hide();
       		$w("#sectionFrontViewVideoYouTube").collapse();
			$w("#sectionFrontViewVideoWixVideo").hide();
       		$w("#sectionFrontViewVideoWixVideo").collapse();
		}

	//FRONT VIEW: Hide the video secitono
	} else {
		$w("#sectionFrontViewStudentsOnly").hide();
        $w("#sectionFrontViewStudentsOnly").collapse();
        $w("#sectionFrontViewBlackBeltsOnly").hide();
        $w("#sectionFrontViewBlackBeltsOnly").collapse();
        $w("#sectionFrontViewVideoYouTube").hide();
        $w("#sectionFrontViewVideoYouTube").collapse();
        $w("#sectionFrontViewVideoWixVideo").hide();
        $w("#sectionFrontViewVideoWixVideo").collapse();
	}

});

});

I can’t figure out the error if it’s possible can you share your page URL?

Also I saw this after your comment. I will try to implement this in a bit:

Maybe a better way…

Looks like that code worked.

Thanks for pointing me towards the new api @loeiks .