Approve By Email - HELP NEEDED

I have been trying for hours to get the code for approveByEmail to work but for some reason it will not work.

I have set up a place where my clients can create an account then enter their email and password. Which that get passed to the register(email,password) function.

I really need help with how the approve by email works because I am trying to change the clients status from “Pending” to “Approved”. I am trying to follow the verbiage in the Wix Code API section but I can’t understand where I should put things in order for the information to work.

I think I work better with an example of how approvebyemail() works

Here is a broad look at my code without getting so complicated with the rest but this is generally how it is set up:


 
export function button2_click(event) {
 eventPress(event)
}
 
 
function eventPress(event, parameter) {
wixData.query("ClientProfileData")
                .eq("logInEmail", userEmail)
                .find()
                .then((results) => {
        //console.log(userEmail + '2')

 let items = results.items;
 let firstItem = items[0];
 
myBackendFunction(userEmail)  // <------ This is where I am trying to approve my client
 .then((theresults) => {
});
 let totalCount = results.totalCount;
 let pageSize = results.pageSize;
 let currentPage = results.currentPage;
 let totalPages = results.totalPages;
 let hasNext = results.hasNext();
 let hasPrev = results.hasPrev();
 let length = results.length;
 let query = results.query;
                })
                .catch((error) => {
 let errorMsg = error.message;
 let code = error.code;
                    console.log(errorMsg)
                    console.log(code)
                    $w("#password").collapse()
                    setTimeout(() => {
 //console.log("Timeout")
                        $w("#text197").text = "Verify your account with your email."
                    }, 1000)
                })
}

 
import wixUsers from 'wix-users-backend';

export function myBackendFunction(email) { //<-------This is where the confusion is happening
    wixUsers.approveByEmail(email)
        .then((sessionToken) => {
 //wixLocation.to("/mydashboard/" + email)
 return { sessionToken, "approved": true }; //<-does this mean that my client status is Approved
        })
        .catch((error) => {
 return { "approved": false, "reason": error };
        });
}

Should I have something in the backend code? Like a .js file of what the approve process is?? Or is the function calling a function that wix has pre-placed in the backend?

Please let me know if I am explaining it right or not.

1 Like

@andreas-kviby Hey could you take a look at this by chance?

Heard you are a guy that could help.