# How do rules work?

**URL:** <https://community.auth0.com/t/how-do-rules-work/68824>\
**Category:** Get Help\
**Tags:** rules, auth0\
**Created:** [August 30, 2021, 10:33pm UTC](https://community.auth0.com/t/how-do-rules-work/68824 "2021-08-30T22:33:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kewyn-Vieira](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kewyn-vieira/32/31451_2.png) [@Kewyn-Vieira](https://community.auth0.com/u/Kewyn-Vieira)\
**Post date:** [August 30, 2021, 10:33pm UTC](https://community.auth0.com/t/how-do-rules-work/68824/1 "2021-08-30T22:33:32Z")

</div>

I started exploring auth0 today and I don’t get how rules are meant to be implemented.

What do I do with this?

```auto
function (user, context, callback) {
  context.idToken["http://mynamespace/hello"] = "world";
  console.log('===> set "hello" for ' + user.name);
  callback(null, user, context);
}

```

should I call it somewhere, or export it and import it to somewhere else, what do I do?

I also can’t find anywhere what types I should give to the arguments when using Typescript.

---

<div class="post-metadata">

**Author:** ![marcus.baker](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcus.baker/32/8586_2.png) [@marcus.baker](https://community.auth0.com/u/marcus.baker)\
**Post date:** [August 31, 2021, 1:43am UTC](https://community.auth0.com/t/how-do-rules-work/68824/2 "2021-08-31T01:43:53Z")

</div>

Hi,

Your rule is attaching a custom claim to an ID Token.  
The ID Token will be returned to your application after the authentication completes.  
your application could consume that claim for some purpose.

Example of ID token with the claim from the rule above:

```auto
{
==> "http://mynamespace/hello": "world",
  "nickname": "marcus.baker@auth0.com",
  "name": "marcus.baker@auth0.com",
  "updated_at": "2021-08-31T01:37:42.520Z",
  "iss": "https://mytenant.auth0.com/",
  "sub": "auth0|dbuser",
  "aud": "4kHx.................eQEm",
  "iat": 16........,
  "exp": 1630......,
  "nonce": "UkJocDVUVGQ4R2VOQkxk......Y0RlT0s2MUZYS0FTflZ0QkU0Yw=="
}

```

We have some use cases for claims documented here: [Sample Use Cases: Scopes and Claims](https://auth0.com/docs/configure/apis/scopes/sample-use-cases-scopes-and-claims)

In addition to Rules, it is worth checking out Auth0 Actions, our newest extensibility tool. All the power of Rules with a much-improved editing and deployment experience.

> **[Auth0 Actions](https://auth0.com/docs/customize/actions)**
>
> Describes Auth0 Actions, which are secure, tenant-specific, self-contained functions that allow you to customize the behavior of Auth0.

Hope this helps!

---

<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:** [August 31, 2021, 2:44pm UTC](https://community.auth0.com/t/how-do-rules-work/68824/3 "2021-08-31T14:44:29Z")

</div>

Thanks for helping on this one Marcus!

---

<div class="post-metadata">

**Author:** ![Kewyn-Vieira](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kewyn-vieira/32/31451_2.png) [@Kewyn-Vieira](https://community.auth0.com/u/Kewyn-Vieira)\
**Post date:** [August 31, 2021, 10:29pm UTC](https://community.auth0.com/t/how-do-rules-work/68824/4 "2021-08-31T22:29:23Z")

</div>

Yes but how do I make it work? Do I just create the rule in the dashboard?

---

<div class="post-metadata">

**Author:** ![marcus.baker](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcus.baker/32/8586_2.png) [@marcus.baker](https://community.auth0.com/u/marcus.baker)\
**Post date:** [September 2, 2021, 1:46am UTC](https://community.auth0.com/t/how-do-rules-work/68824/5 "2021-09-02T01:46:30Z")

</div>

Hey!

Yes, you would put that code in the editor window in a new Rule.

From the dashboard - click:

> Auth Pipeline  
> Rules  
> Create  
> Empty Rule

The new rule editor should load in the dashboard.

 ![Screen Shot 2021-09-01 at 6.45.39 PM](https://global.discourse-cdn.com/auth0/original/3X/5/9/59dcb954451ff0a35bf24070457d560747802ccf.png)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 17, 2021, 1:47am UTC](https://community.auth0.com/t/how-do-rules-work/68824/6 "2021-09-17T01:47:11Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
