roles w

role.jsw:

 

import {roles} from 'wix-users-backend';

 

export function assignRole(roleId, memberId) {

return roles.assignRole(roleId, memberId, { suppressAuth: false })

.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 role

assignRole(roleId, results.user.id);

}

});

 

 

Please any help!

 

 

Answer

 

0

 

Share

 

2

 

Sneha Shah

BEST ANSWER

·

20h

 

Only change u need to do is: suppressAuth: true

 

 

export function assignRole(roleId, memberId) {

return roles.assignRole(roleId, memberId, { suppressAuth: true })

.then( () => {

console.log("Role assigned to member");

})

.catch((error) => {

console.log("failed to assing role"+ error);

});

}