Hi, question. I’ve build a custom sign-up and want to include AssignRole in the same code. But I don’t quite understand how to connect those in one script.
Ideal result: Registered New member with assigned member role.
What I have now is:
// API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world
// $w.onReady(function () {
// Write your JavaScript here
// To select an element by ID use: $w("#elementID")
// Click "Preview" to run your code
//});
///end original
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import {roles} from 'wix-users-backend';
$w.onReady(function () {
$w('#submit').onClick( () => {
let emails = [];
let labels = [];
let location = [];
emails.push($w('#email').value);
// register as member using form data
wixUsers.register($w('#email').value, $w('#password').value, {
"contactInfo": {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"emails": emails,
"labels": labels,
// "height": Number($w('#height').value)
}
});
export function assignRole(roleId, memberId)) {
return roles.assignRole(roleId, memberId, { suppressAuth: false })
.then( () => {
console.log("Role assigned to member");
})
.catch((error) => {
console.log(error);
});
//}
});
});
});
//});
Can anybody help me out with this?
Thanks