Getting "createMember(member)" to work

I’m trying to set up a way to create a new user from within the site. I don’t want them to have to logout, then log back in for it to be done.

I have found “createMember” and I’m trying to implement it. However, it’s not working for me.

I’m getting this error message:

image

Is anyone able to point me in the right direction/show me the correct code I need to be using? This is my page code:

export function button6_click(event) {

let slug = $w(“#input2”).value;
let nickname = $w(“#input1”).value;

let member = {
contact: {
emails: [${slug}@test.com]
},
profile: {
nickname: nickname,
slug: slug
},
loginEmail: ${slug}@test.com
}

console.log(${slug}@test.com);

createMember(member)

}

async function createMember(member) {

//const members = wixAuth.elevate(createMember.member);
try {
const result = await members.createMember(member);
return result;
} catch (error) {
console.error(error);
console.log(“threw an error”);
// Handle the error
}
}

I’m trying to set up a way to create a new user from within the site. I don’t want them to have to logout, then log back in for it to be done.

Question: What for do you need this functionality? Who will use this function & why?
Why for example an already registered and logged-in user (member) should create a further member-acoount?

Or is it you as ADMIN → who wants to create members from within your site (page) ?

Reading just this sentence…

I’m trying to set up a way to create a new user from within the site.<

I understand, that this function is wanted from the view of an ADMIN.

But reading the next sentence →

I don’t want them to have to logout, then log back in for it to be done.

…confuses again.

So what is your exact goal? Please describe a bit more in detail and explain what for you need this?

Futher, pay attention, that working just on FRONTEND → you will face → RESCTRICTIONS (security-reason). As i can see, your code is a FRONT-END-CODE → that means you may not have the rights, you normaly would get/have on BACKEND.
So instead of using FRONTEND-API → you may better try to generate a BACKEND-CODE.

There are only 2 APIS which would help you as of my knowledge…

  1. Wix-Members-Backend-API
  2. Wix-CRM-BackendAPI
    In this both APIs also APIs like LOGIN/LOGOUT (AUTHENTICATION) should be included, as i can remember.

Hi @CODE-NINJA

Thanks for the message and further info. Sorry about the late reply.

I managed to get this working. I put it in the backend, but it also needed “elevated permissions” to work.

The functionality is for agencies. I want them to have a master login, and then be able to add new accounts for each client they onboard. This way, they can see a list of accounts linked to the master account and switch between them easily.

Thanks again!