@conormcleod
Well there are some mistakes in your code.
The first one is located directly in your FIRST codeline of your frontend-code…
Instead of this one…
import wixUsersBackend from 'wix-users-backend';
You surely wanted to do this one…
import {assignRole} from 'backend/roles.jsw';
You do not want to import wix-users-backend to your frontend!
You want to import your exported function, called → assignRole() .
And the second one is now provided by me, which will give you all needed informations about the USER directly from the BACKEND, called → get_userData()
So you have now two exported functions running on your BACKEND.
- get_userData()
- assignRole()
Now you will have to call first the get_userData-function to get all informations about the current logged-in USER.
After you have done this, you can take all collected informations about the current logged-in user, to use this information in your next step → assigning a role to the current logged-in-user.
Your code then would look like the following…
FRONTEND-CODE:
import {get_userData(), assignRole()} from 'backend/roles.jsw';
$w.onReady(function() {
$w('#anyButtonIDhere').onClick(async()=>{console.log("Button clicked!");
let userData = await get_userData(); console.log("DATA: ", userData);
console.log("USER: ", userData.USER);
console.log("User-ID: ", userData.userID);
console.log("User-Logged-In: ", userData.loginSTATUS);
console.log("User-Email: ", userData.userEmail);
console.log("User-Roles: ", userData.userRoles);
// first take a look onto the given RESULT-OUTPUT in your CONSOLE!!!
// make clear how to continue...
// CONTINUE here to assign the right chosen role.....
assignRole(userData.userRoles[0], userData.userID);
});
});
BACKEND-CODE: —> roles.jsw
export async function get_userData() {
let USER = await wixUsersBackend.currentUser;
let userID = await USER.id;
let isLoggedIn = USER.loggedIn;
let userEmail = await USER.getEmail();
let userRoles = await USER.getRoles();
let DATA = {}
DATA.USER = USER;
DATA.userID = userID;
DATA.loginSTATUS = isLoggedIn;
DATA.userEMAIL = userEmail;
return(DATA)
}
export function assignRole(roleId, memberId) {
return roles.assignRole(roleId, memberId, {suppressAuth: true})
.then(() => {console.log("Role assigned to member");})
.catch((error)=> {console.log(error);});
}
Now you normaly should be able to complete your task. Good luck! 
To see a working example, take a look at this one…
https://russian-dima.wixsite.com/login-system/vnloginmgm
- Navigate first to the SETUP and CHECK if the MAIN-REGISTRATION-OPTION is activated…
If not, change it to → “MAIN” by activating the SETUP-OPTIONS → PW=“12345”
Please do not touch other SETUP!
- SAVE the changed OPTIONS!
- Navigate back to REGISTRATION/SIGN-UP-PAGE…
4) Click on → " + " -SIGN a new option-window will appear…
5) You can now see a ROLE-OPTION which you can choose (just one ROLE is ACTIVATED). If you want to activate a further ROLE, and you do not know how to do that —> take alook here …
https://russian-dima.wixsite.com/login-system/info
3-different ROLES are AVAILABLE in this INTERACTIVE-EXAMPLE.
- You can run a test, by doing a complete registration, or you just use the already given LOGINs to check for further functionalities and features.
At the end you will recognize that everything works and you are able even to assign roles directly on registration.
Have fun!