I understand how to use let and get to receive information about a user’s certain role. But how can I set a Member’s Role using Wix Code or even setting a Member’s Role as something if they click a certain button? Any help?
Thanks.
I understand how to use let and get to receive information about a user’s certain role. But how can I set a Member’s Role using Wix Code or even setting a Member’s Role as something if they click a certain button? Any help?
Thanks.
a sample hopefully useful for your business
$w.onReady(() => {
let ktos = wixUsers.currentUser;
if (ktos.loggedIn) setupPage();
wixUsers.onLogin((user) => {
setupPage();
});
});
export function setupPage() {
let user = wixUsers.currentUser;
user.getRoles()
.then((roles) => {
if (roles.length === 0){
$w(“#menu”).show();
$w(“#menuobsluga”).hide();
$w(“#klientgroup”).hide();
}
else {
let firstRole = roles[0];
let roleName = firstRole.name;
//console.log(roles);
//console.log = (roleName); // “Role Name”
let roleDescription = firstRole.description; // “Role Description”
if (roleName === “obsluga” && user.loggedIn) {
$w(“#menu”).hide();
$w(“#menuobsluga”).show();
$w(“#klientgroup”).hide();
}
if (roleName === “Klient” && user.loggedIn) {
$w(“#menu”).hide();
$w(“#klientgroup”).show();
$w(“#menuobsluga”).hide();
}
else {
$w(“#menu”).show();
$w(“#klientgroup”).hide();
$w(“#menuobsluga”).hide();
}
}})
}
So I believe until today is not yet possible to set role members, is it ?
At this time it isn’t. I think we can work around this by adding labels to CRM or our own collections and querying them
I need this functionality, Wix, could you please add a way to manage user roles programmatically?
You can’t do it through code, only manually.
https://support.wix.com/en/article/creating-member-roles-6943237
https://support.wix.com/en/article/managing-your-member-roles
https://support.wix.com/en/article/changing-the-permissions-of-a-member-role
https://support.wix.com/en/article/limiting-pages-on-your-site-to-specific-members-member-roles
All you can do so far is to get the role of the member when they are logged in and go from there.
https://www.wix.com/corvid/reference/wix-users.User.html
Been asked on other previous forum posts too.
https://www.wix.com/corvid/forum/community-discussion/create-member-role-member-type-on-sign-up
Hi Marcelo,
If you really need this feature it can be code via routers:
https://www.wix.com/corvid/reference/wix-router.html
https://www.wix.com/corvid/reference/wix-router.html#beforeRouter
you can create logic that redirect user to another page if conditions are not met
would that be a suitable solution for you?
@plomteuxquentin
Would be a bit of a long winded way to work around the issue.
Would be much, much easier if they got around to giving us the option to assign a member role in code already
Wix Devs, we are waiting for you, pretty please
@givemeawhisky true this would solve many challenges I have in my projects.
But if Marcelo need it now this is the way
Sir Whisky is right.
We need this feature.
@plomteuxquentin I don’t think this works. The use case is this:
I want to be able to set Role in the backend, like most other user attributes.
Also need to set Password in the backend. C’mon Wix devs!
@marcelo25925 That’s not possible to create an account, nor to set a password. This is sensitive data and I guess Wix want to play it safe. So that will not be possible in Wix (and I would not recommend creating a custom membership system even though it’s possible)
The custom roles system is possible to do with the router though. It would allow blocking page access based on custom user roles.
But why do you use TypeForm to register the user? Why don’t you use custom registration within Wix? It would solve half of your problems.
Is this a thing yet? It’s extremely tedious to assign user roles manually. Roles should be able to be determined based on sign up form responses.
Unfortunately not, you can try setting yourself up a router like @plomteuxquentin has stated, otherwise you will still have to do it manually.
If you look at this Wix example here for Stripe Payments, you can see the router setup and working for the different pages on this exmaple.
https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-stripe-payment-processing
This is the thing I wanted to do with my site too! Wix, hear us.
I need this feature
Old post being closed.