Moralis help wanted: How to remove an user added to Role table?

Hi,

I am using the Role table and abilities of the Moralis server.
See: https://docs.moralis.io/moralis-sdk/roles

I can add an user to an earlier created rolename (ex. ‘admin’): via:

  let roleName = 'admin';
  const roleACL = new Moralis.ACL();
  roleACL.setPublicReadAccess(true);
  let role = new Moralis.Role(roleName, roleACL);
  role.getUsers().rem(request.user);      
  role.save();

But how to remove a user from a role?

What is function of the roles relation field?

Items can be removed from a relation via
role.getUsers().remove(user)

It functions the same way as relations for objects:
https://docs.moralis.io/moralis-sdk/objects#relational-data

The “roles” relation is for creating “Role Hierarchies”. If a role references other roles through it’s Roles relation it will inherit ALL those roles. See the docs on Role Hierarchies:
https://docs.moralis.io/moralis-sdk/roles#role-hierarchy

1 Like