My code for the page is
import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import {assignRole} from 'backend/role'; $w.onReady(function(){ $w('#register').onClick(function (){ 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(()=> { wixLocation.to('/dashboard1'); }) .then(() => { let email=$w("#email").value; let roleId="d990f333-d091-4670-ad29-f3a6d5e88f3f"; assignRole(roleId, email); } ) } )})
And the role.jsw code is
import {roles} from 'wix-users-backend'; export function assignRole(roleId, email) { return roles.assignRole(roleId, email, { suppressAuth: true }) .then( () => { console.log("Role assigned to member"); }) .catch((error) => { console.log(error); }); }
assignRole() function has two parameters :Role_Id and member_Id not email !
assignrole(roleId, memberId)
just change the member id parameter from email to member_Id
https://www.wix.com/velo/reference/wix-users-backend/roles-obj/assignrole
wixUsers.register(email, password,{ contactInfo:{"firstName": first,"lastName": last }}) .then((result)=>{ let roleId="d990f333-d091-4670-ad29-f3a6d5e88f3f"; assignRole(roleId, results.user.id); wixLocation.to('/dashboard1');}). }
try the code above it will work with you