0

I'm trying to return few data from backend to frontend once the registration is complete. While testing I can see that the user gets registered successfully but for some reason, the data I return from the backend method to the frontend comes with "undefined".

Below is my Backend Code.

export function doRegistration(email, password, firstName, lastName) {
    wixUsersBackend.register(email, password, {
        "contactInfo": {
            "firstName": firstName,
            "lastName": lastName
        }
    }).then((result) => {
        if (result.status === "Pending") {
            wixUsersBackend.approveByToken(result.approvalToken)
                .then((token) => {
                    return {
                        "approved": true,
                        "userId": result.user.id,
                        "isEmailExist": false
                    }
                }).catch((err) => {
                    return {
                        "approved": false,
                        "isEmailExist": false,
                        "errorCode": err.errorCode,
                        "errorMessage": err.errorDescription
                    }
                });
        }
    }).catch((err) => {
        return {
            "approved": false,
            "isEmailExist": true
        }
    });
}

I tried reading the return value from frontend in both the ways as follow:

doRegistration($w('#txtLoginEmail').value, $w('#txtPassword').value, $w('#txtFirstName').value, $w('#txtLastName').value).then(result => {
                if (result.approved) { //.approved is undefined
}
});

Also,

let result = doRegistration($w('#txtLoginEmail').value, $w('#txtPassword').value, $w('#txtFirstName').value, $w('#txtLastName').value);
if (result.approved) {  //.approved is undefined
}

Any help on this will be greatly appreciated.

Thanks, Jilu

1 Answer 1

0

I think its because you are not catering for a scenario where the result.status is not "Pending" Try the below

if (result.status === "Pending") {
      wixUsersBackend.approveByToken(result.approvalToken)
      .then((token) => {
           return {
              "approved": true,
              "userId": result.user.id,
              "isEmailExist": false
           }
           }).catch((err) => {
               return {
                  "approved": false,
                  "isEmailExist": false,
                  "errorCode": err.errorCode,
                  "errorMessage": err.errorDescription
               }
           });
} else {
      return {
         "approved": true,
         "userId": result.user.id,
         "isEmailExist": false
       }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.