[Bug] currentUser.getRoles broken

I’m getting “Error: Not Found: the requested item no longer exists.” when calling getRoles in code which previously worked fine (for many months).

The following is code that runs in the backend. I get to the first log print but not the second.

let user = wixUsers.currentUser;
    console.log("in gtps");
 return user.getRoles()
        .then((roles) => {
            console.log("in then of getRoles");

@Brett Haralson (Wix)

1 Like

Can you post your entire code?
it should be:

import wixUsersBackend from 'wix-users-backend';
//...
let user = wixUsersBackend.currentUser;

since it’s on the backend

  • as you can see in the other thread, you can’t get roles with backend code. so you’ll have to get them on the front-end and pass to the backend.

Thank you @jonatandor35 .
What other thread?
It is possible to get the current user, and via the user to get the role. At least it used to be. It was working before. And this was the recommended way (somewhere) to get protected data to the Admin. Did this change? And if so, is there now another way to verify the Admin?
Obviously, as this is in order to protect sensitive information, providing the role from the front-end doesn’t help.

Here’s a fuller excerpt from the code:


import wixUsers from 'wix-users-backend';
import wixData from 'wix-data';

export function gtps(userID) {
 let user = wixUsers.currentUser;
    console.log("in gtps");
 return user.getRoles()
        .then((roles) => {
            console.log("in then of getRoles");

https://www.wix.com/corvid/reference/wix-users-backend.html#currentUser clearly shows an example of getting the user’s role this way in the backend

OK, I found the other thread you were talking about, sorry I missed that. The original response there was incorrect, it should in fact be supported. But it was just reported as fixed, and it is. So we’re good! Thanks again, @jonatandor35

Hi, we had an issue with this API, it was fixed and it should work now. can you please recheck?