Get ROLE for connected USER (isAdmin cloud function)

Hello guys !

I have a problem with a feature that i want to do : create a cloud function that return a boolean true/false if the current User is Admin or not.

  • Gets all Roles in the database (WORK Fine) (But can’t access to Users relation from Roles)
  • Can’t get the current user and his role list to check if he has the admin role…
    I can’t find any information in the documentation, how i can retrieve the user and his roles ?
    I can see this object ID in cloud function logs, but can’t retrieve it.
    I tried : Use Moralis SDK Moralis.User.current(); (return undefined), Roile.getUsers() (return undefined)
    request.user (return undefined)

The user is correctly connected on my dapp before call cloud function : Moralis.User.current() return the current user on my dapp no problem.

Some one can help me plz ?

you can query the role table specific to admin role, and check there if a particular user is present

Thanks for your answer, but i did it already, on my screen, you can see that i get the admin role no problem with it.
The question is, how i can find the users attached to the role, and compare it with the current user that make the cloud function call plz ?

Thanks

You mean that you don’t know how to list the users attached to a specific admin role by querying the database?

1 Like

Try this solution:

1 Like

OK thanks, yes my first problem was i don’t know how to list the users attached to a specific admin :slight_smile: With your answer i will be able to get all USERS attached to the admin _Role. Nice :slight_smile:

The last thing is : How get the current user or object ID from the user that called the cloud function to compare with the result of the query ? :slight_smile:

you have that info in the request parameter for the cloud function, you can use
logger.info(JSON.stringify(request)) to see what is there, or return request and log it in frontend

1 Like

@cryptokid Thanks a lot for your help, you solved my problem !

I post the complete code if some one is interested :

2 Likes