Remove a resource

Remove a resource from a role instance.

Remove a resource

You can remove a resource from a role instance by using the remove method.

const role = new Role({
    name: 'role',
    config: {
      user: {
        base: 'crudl',
        custom: {
          ban: false
        }
      },
      post: {
        base: '-rudl',
        custom: {
          publish: true
        }
      }
    }
});

const updated = role.remove({
    resource: 'post'
}); // returns a new role instance

role.getResources() // ['user', 'post']
updated.getResources() // ['user']

The remove Method: Removing Resources from a Role

The remove method eliminates a specific resource and its associated permissions from a role. It accepts an object with these properties:

  • resource (string): Name of the resource to remove.
  • mutate (boolean, default: false): Optional. If true, modifies the existing role instead of returning a new instance.

The method returns a new role instance by default, with the specified resource removed.

You can use the getResources method on role instances to retrieve a list of current resources. This allows you to verify the removal and track available resources.

This method enables dynamic adjustment of role capabilities by removing unnecessary or outdated resource permissions, supporting flexible access control management.