# Add rules to saveUser for a token

**URL:** <https://discourse.getcockpit.com/t/add-rules-to-saveuser-for-a-token/352>\
**Category:** Support\
**Created:** [October 22, 2018, 5:09pm UTC](https://discourse.getcockpit.com/t/add-rules-to-saveuser-for-a-token/352 "2018-10-22T17:09:59Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [October 23, 2018, 8:14am UTC](https://discourse.getcockpit.com/t/add-rules-to-saveuser-for-a-token/352/4 "2018-10-23T08:14:05Z")

</div>

I still think that collections would be more flexible as you can extend the user fields as you need (e.g. multiple roles, address, etc…), the intent of cockpit users is just to manage the CMS.

You can put inside a bootstrap.php file in an addon (e.g. /addons/users/bootstrap.php), a more complete example can be:

```
<?php
if (COCKPIT_API_REQUEST) {
  $app->on('cockpit.accounts.save', function (&$data, $update) {
    // Any additional logic you may require (check if request is from the api, etc..)
    if (in_array($data['group'], ['admin', 'other admin groups'])) {
      unset($data['group']);
    }
  });
}
```

---

_[View the full topic](https://discourse.getcockpit.com/t/add-rules-to-saveuser-for-a-token/352)._
