Hi, I have set up a custom sign up form inside a lightbox to allow a different set of users (other than regular wix members) to create their account on the website.
What I wish to achieve with the following code is to register a user with authentication.register(), and then assign to the user a specific role (in this case: ‘Partner’), and finally redirect the user to the wix members’ page.
// FRONTEND: lightbox with custom sign up form
import { authentication } from 'wix-members';
import wixLocation from 'wix-location';
import { assignRole } from 'backend/role';
$w.onReady(() => {
$w('#registerNow').onClick(() => {
let email = $w('#email').value;
let password = $w('#password').value;
let company = $w('#companyName').value;
authentication
.register(
email,
password,
{contactInfo: {"companyName": company}}
)
.then(results => {
const roleId = "3d8c5945-4ab3-4c5f-9cea-0e1f56d34d56"; // 'partner' role's ID
assignRole(roleId, results.member._id);
})
.then(() => {
wixLocation.to('/members');
})
})
});
// BACKEND: function used to assign role to a user
export const assignRole = (roleId, memberId) => {
return (
roles.assignRole(roleId, memberId, { suppressAuth: true })
.then(() => {
console.log("Role assigned to member");
})
.catch((error) => {
console.log(error);
})
);
}
It used to work fine in the beginning (after submitting the form, the new account was saved in the members’ list with the appropriate role (‘partner’) and the users was redirected to the ‘/members’ page).
For some reasons now when i try to create a new account by submitting the sign up form I get the following error in the console: Error: Cannot read properties of undefined (reading ‘status’) .
I would very much appreciate some help! Cheers.