Problem with authentication.register() - Error: Cannot read properties of undefined (reading 'status')

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.

1 Like

I have the same issue

import { authentication } from ‘wix-members’ ;

let emails = [];
let phones = [];

$w . onReady ( function () {

$w ( ‘#register’ ). onClick ( () => {
const password = $w ( ‘#password’ ). value ;
const email = $w ( ‘#email’ ). value ;
const phone = $w ( ‘#phone’ ). value ;

emails . push ( email );
phones . push ( phone );

let options = {
contactInfo : {
firstName : $w ( ‘#firstName’ ). value ,
lastName : $w ( ‘#lastName’ ). value ,
emails : emails ,
phones : phones ,
},
privacyStatus : ‘PUBLIC’
}

authentication . register ( email , password , options )
. then (( registrationResult ) => {
const status = registrationResult . status ;
if ( status === “PENDING” ) {
const approvalToken = registrationResult . approvalToken ;
console . log ( ‘Member registered and waiting for approval:’ , registrationResult );
} else {
console . log ( ‘Member registered and logged in:’ , registrationResult );
}
})
. catch (( error ) => {
console . error ( error );
});
});
});

I later realised that I cannot check to see if the code works in preivew, turns out its working fine on the live site - i guess u can’t preview everything