Not really sure what your problem is. Perhaps either the userId or roleId is incorrect?
I created a test site. After running the site Live, I look in site Dashboard and see that the user (me for purposes of testing) has been added to the role.
The frontend code:
export function button1_click(event) {
let userId = wixUsers.currentUser.id;
let roleId = < the id for the role >;
assignRole(roleId, userId).then(() => {
console.log('done');
})
.catch(error => {
console.log(error);
});
}
I used a button to prevent the code from running twice in the onReady() - once server side, and then in the browser.
The backend code:
import {roles} from 'wix-users-backend';
export function assignRole(roleId, memberId) {
return roles.assignRole(roleId, memberId, { suppressAuth: true })
.then( () => {
console.log("Role assigned to member");
})
.catch((error) => {
console.log(error);
});
}
The code is pretty much the same as yours. I ran my test site, clicked the button, got the message “Role assigned to member”, and then saw in the site Dashboard that the role was assigned.