[SOLVED] Member role does not change

Hello, I’m having troubles with the custom roles in the CRM section. I registered another account just to test it out and assigned the “Admin” role to it.

However, when I login and check the console, it still shows up as “Member”

Here’s the code I used to check:

$w.onReady(function () {
let currentUser = wixUsers.currentUser; console.log("Current-User: ", currentUser);
let userRole = wixUsers.currentUser.role; console.log("User-Role: ", userRole);
  
   if (currentUser.loggedIn) {
     $w('#loginBtn').hide()
         $w('#loginBar').show()
         if (currentUser.role === 'Admin') {
               //show or hide elements here:
               $w('#adminMenu').show();
               $w('#memberMenu').hide();
         }
         if (currentUser.role === 'Member') {
               $w('#memberMenu').show();
               $w('#adminMenu').hide();
         }
      }
});

The only account that shows up as “Admin” is my other account which I used to create the website.

Where did you do the role assignment?

When you take a look onto the following example…

https://russian-dima.wixsite.com/login-system/vnloginmgm

You can use an already predefined Account or you can create a new own one.
Login and take a look which ROLE is displayed on top of the main LOGIN.

  1. When you log-in as —> STUDENT…

  1. When you login as Teacher (ok this one is blocked) :grin:

  1. When you log-in with → mr@president.com


So everything seems to work.

REGISTER your own new ACCOUNT and test it out by your own…


Current Role-Setup for —> GAMER:

Setup your own new ROLE in the ROLE-SETUP…

More info to be found here…

https://russian-dima.wixsite.com/login-system/info

Thanks for responding! I assigned the role via Wix Dashboard. I made sure to test it using the Published website but the role of the user is still “Member”.

@chocookie22 I can’t tell you what causes the issues in your setup, but i quickly did a TEST and changed the ROLE for —> mr@president.com

—> from → GAMER
—> to -----> PRESIDENT

This is the result…


Everything works like a charm.
The changement was done in the Wix integrated DASHBOARD (Member-Management).

Perhaps deleting completely existing account and REGISTER one more time.
When deleting → pay attention that you delete from Wix-CRM and from PMD.

Wix-CRM → CONTACTS
PMD → PrivateMembersData
or by CODE…
https://www.wix.com/velo/reference/wix-users-backend/deleteuser

@russian-dima This is really weird. Just to confirm, this is correct, right?

let currentUser = wixUsers.currentUser; console.log("Current-User: ", currentUser);
let userRole = wixUsers.currentUser.role; console.log("User-Role: ", userRole);

If this is correct or not, this question will be answered by your best friend → the CONSOLE.

What does give you the console as RESULTS ?
At first look, it looks good → but always investigate the RESULTS in CONSOLE.

And my additionial tip → i do testings always just on published site!

@russian-dima The console displays the correct info except for the role.
I just deleted the records from both Contacts and PrivateMembersData and registered again. I then assigned the “Admin” role to that user but it still shows up as “Member” in the Console results.

@chocookie22 Open all RESULTS in CONSOLE + do a screenshot.
I never tested it, but perhaps → “Admin” is a preconfigured one which can’t be changed.
Did you try to test your issues with a different one? Create another role. Test it. Still the same problem ?

BTW: Perhaps this post will give you new ideas…

@russian-dima Here’s a screenshot of the result in console:

I just really want to set a custom role (Admin) so I can show/hide a menu. If there’s an alternative way of doing this, I’m open for suggestions.

@russian-dima I just want to make sure I’m doing everything right.
This is the way to add a new role right?

And this is how you add a member to that role:

I added the new account there as a member but when I check the console result of the published website, it still shows as “Member”.

Are you sure → that you are logged-in?
You can also test your login-state and see result in console.

Ok, this question is resolved → yes you are…

I created right now the → “Admin”-Role and asigned my own test-account to it.
That means when i login with that test-account → it should show me → “Admin”, let’s take a look…

SURPRISINGLY RESULT! (but why?)

Hmmm taking a closer look —> Hey, he has two different roles!

That means we must have an ARRAY, filled with different roles?
roles = [PRESIDENT, Admin]
roles[0] = —> PRESIDENT
roles[1] = —> Admin

What if i delete the PRESIDENT-ROLE? → Just Admin left…

Relog again…and what do we get now ???..
HURAAAAYYYYYY! Now instead of PRESIDENT —> we got Admin!

Could this be also the problem in your case? 2 or more different ROLES for the same USER ?

@russian-dima Can you check the screenshots of my previous reply if the process of creating a new role and adding a new member to it is correct? I really appreciate your time and help.

To answer your most recent reply, I made sure that the test account only has one role assigned to it but it still shows “Member”.

@chocookie22 Yes your steps looks to be right.

Mu suggestion would be —> create a new project.
Setup a complete new MEMBERS-AREA (MEMBER-APP).

Create 2-3 new accounts and assign them different roles.
Take a look if you still have that issues.

Alright, I’ll go ahead and do that. I’ll post the results here in a couple of minutes.

@russian-dima I just created a new project with a newly added Members Area. I registered my test account and assigned it with the “Player” role.

Here’s the code:

Unfortunately, it still shows up as “Member” in the console results.

I really don’t know what to do at this point. :frowning:

Hello @russian-dima , maybe it’s a bug because it’s working for you and not for me. I’ve been working on this for a couple of days already and it looks like I’m at a dead end. I will try to look for other options.

If you want you can send me an e-mail, you will find my contact in my profile.
Maybe i can take a look onto your issue to figure out, whats the real problem.