# Using a function in multiple rules

**URL:** <https://community.auth0.com/t/using-a-function-in-multiple-rules/10821>\
**Category:** Get Help\
**Tags:** rules\
**Created:** [April 12, 2018, 6:43am UTC](https://community.auth0.com/t/using-a-function-in-multiple-rules/10821 "2018-04-12T06:43:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenneth.leine.schuls](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kenneth.leine.schuls/32/8458_2.png) [@kenneth.leine.schuls](https://community.auth0.com/u/kenneth.leine.schuls)\
**Post date:** [April 12, 2018, 6:43am UTC](https://community.auth0.com/t/using-a-function-in-multiple-rules/10821/1 "2018-04-12T06:43:51Z")

</div>

We have multiple rules and some of the rules use functions that is assigned to the global object. This is done in a rule running first in the “rule chain”, like so:

```
if (!global.foo) {
  global.foo = function () { };
}

```

This _used to be_ recommended approach according to the Auth0 rules documentation:

> **[Auth0 Rules - Auth0 Docs](https://auth0.com/docs/customize/rules)**
>
> Learn about Rules and how you can use them to customize and extend Auth0's capabilities.

However, in the _current_ [rules documentation](https://auth0.com/docs/rules/current), this section has been removed.

Are there any other (and better) ways to accomplish this? E.g. `require`-ing the functions instead?

---

<div class="post-metadata">

**Author:** ![jerdog](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerdog/32/11231_2.png) [@jerdog](https://community.auth0.com/u/jerdog)\
**Post date:** [April 12, 2018, 2:28pm UTC](https://community.auth0.com/t/using-a-function-in-multiple-rules/10821/2 "2018-04-12T14:28:11Z")

</div>

The legacy approach will continue to work for the time being (at least 6 months), though there currently is not a better alternative for _rules_ at this time.

---

<div class="post-metadata">

**Author:** ![kenneth.leine.schuls](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kenneth.leine.schuls/32/8458_2.png) [@kenneth.leine.schuls](https://community.auth0.com/u/kenneth.leine.schuls)\
**Post date:** [April 19, 2018, 12:45pm UTC](https://community.auth0.com/t/using-a-function-in-multiple-rules/10821/3 "2018-04-19T12:45:35Z")

</div>

Thanks! And from the wording of your response I assume that the support for this approach might be phased out at some time?

---

<div class="post-metadata">

**Author:** ![jerdog](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerdog/32/11231_2.png) [@jerdog](https://community.auth0.com/u/jerdog)\
**Post date:** [April 19, 2018, 12:50pm UTC](https://community.auth0.com/t/using-a-function-in-multiple-rules/10821/4 "2018-04-19T12:50:15Z")

</div>

Not exactly - as we migrate the platform for Rules this approach may or may not work - we don’t know right now. However, in the _new world_ for rules/hooks all npm modules should be available so that would be the preferred option.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2018, 10:46am UTC](https://community.auth0.com/t/using-a-function-in-multiple-rules/10821/5 "2018-12-17T10:46:44Z")

</div>


