top of page

Forum Posts

d4wsqjksbh
Jun 01, 2023
In Coding with Velo
I'm unable to get the following code to assign a role to members upon registration. Would really appreciate if anyone could please point out what's wrong. Thanks! // Custom signup import { authentication } from 'wix-members'; import { assign } from 'backend/role'; $w.onReady(function () { // Click "Run", or Preview your site, to execute your code $w('#button2').onClick ((event) => { const email = $w('#input2').value; const password = $w('#input1').value; const options = { contactInfo: { firstName: $w('#input4').value, lastName: $w('#input3').value } }; var role = ""; if ($w('#dropdown1').value=="Employer") { role = "c02c480a-20ae-4cd7-85ff-d0d00d60ecda"; } else if ($w('#dropdown1').value=="Employee") { role = "32c341be-8b80-4dec-ab82-8d39f729680c"; } console.log(role); authentication.register(email, password, options).then((results) => { console.log("Hit correct branch"); assign(results.member._id, role); console.log("Successfully assgined role"); }) .catch((error) => { console.log("Hit error branch"); console.error(error); }; }); }); // backend/role.jsw import { authorization } from 'wix-members-backend'; export function assign(member, role) { const roleId = role; const memberId = member; return authorization.assignRole(roleId, memberId, {suppressAuth: true}) .then(() => { console.log("Role assigned to member"); }) .catch((error) => { console.error(error); }); } When I try to sign up and open the web console, only the role ID would be printed (`console.log(role)`) but "Hit correct branch" would not be printed.
0
1
10
d4wsqjksbh
May 24, 2023
In Coding with Velo
I've tried the following code, but assigning roles doesn't work. Would really appreciate if anyone can please point out what's wrong. Thanks! // Custom signup import { authentication } from 'wix-members'; import { assign } from 'backend/role'; $w.onReady(function () { // Click "Run", or Preview your site, to execute your code $w('#button2').onClick ((event) => { const email = $w('#input2').value; const password = $w('#input1').value; const options = { contactInfo: { firstName: $w('#input4').value, lastName: $w('#input3').value } }; var role = ""; if ($w('#dropdown1').value=="Employer") { role = "c02c480a-20ae-4cd7-85ff-d0d00d60ecda"; } else if ($w('#dropdown1').value=="Employee") { role = "32c341be-8b80-4dec-ab82-8d39f729680c"; } console.log(role); authentication.register(email, password, options).then((results) => { console.log("Hit correct branch"); assign(results.member._id, role); console.log("Successfully assgined role"); }) .catch((error) => { console.log("Hit error branch"); console.error(error); }); }); }); // backend/role.jsw import { authorization } from 'wix-members-backend'; export function assign(member, role) { const roleId = role; const memberId = member; return authorization.assignRole(roleId, memberId, {suppressAuth: true}) .then(() => { console.log("Role assigned to member"); }) .catch((error) => { console.error(error); }); } When I try to sign up and open the web console, only the role id would get printed (`console.log(role)`), but "Hit correct branch" would not be printed.
0
0
8

d4wsqjksbh

More actions
bottom of page