Hi. sorry not very savvy with this type of code. I found a code that seemed to work for someone else. In my case, I have multiple roles. I have Seller, Agent, and Staff roles. My question is, how does the system know which role to assign? Do I need to add something else to the code? See below the code I found.
Can I add a radio button for the user to select which role they are registering for on login? If so, how would I code it?
JSW
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);
});
}
register page code:
import {assignRole} from 'backend/role';
function registerTeacher() {
let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#fname").value;
let last = $w("#lastName").value;
wixUsers.register(email, password, {
contactInfo: {
"firstName": first,
"lastName": last
}
})
.then((results) => {
let roleId="be13f34e-cf4a-4f33-ae7f-c2313d824206";//Teacher roleassignRole(roleId, results.user.id);
}
});