# I need help converting a rule to action

**URL:** <https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [May 10, 2024, 3:13pm UTC](https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858 "2024-05-10T15:13:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![paperjt](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@paperjt](https://community.auth0.com/u/paperjt)\
**Post date:** [May 10, 2024, 3:13pm UTC](https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858/1 "2024-05-10T15:13:13Z")

</div>

```auto
function addClasslinkTenantIdToAccessToken(user, context, callback) {
    if (context.connection.match(/Classlink/)) {
        context.accessToken.classlink_tenant_id = user.classlink_tenant_id
    }
    return callback(null, user, context)
}

```

When I’m using the action editor the data shape looks very different. In the action the only property for accessToken is a string and not an object so I’m not sure how to convert that part.

What I have now

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.connection.name.match(/Classlink/)) {

  }
};

```

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 10, 2024, 4:52pm UTC](https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858/3 "2024-05-10T16:52:03Z")

</div>

Hey @paperjt welcome to the community!

You’ll want to test of course, but I think the following should work:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Check if the connection type includes "Classlink"
  if (event.connection.name.match(/Classlink/)) {
    // Assign the classlink_tenant_id from the user profile to the access token as a custom claim
    const classlinkTenantId = event.user.classlink_tenant_id;
    api.accessToken.setCustomClaim('classlink_tenant_id', classlinkTenantId);
  }
};

```

---

<div class="post-metadata">

**Author:** ![paperjt](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@paperjt](https://community.auth0.com/u/paperjt)\
**Post date:** [May 10, 2024, 6:09pm UTC](https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858/4 "2024-05-10T18:09:16Z")

</div>

> [@ty.frith](#):
>
> `api.accessToken.setCustomClaim('classlink_tenant_id', classlinkTenantId);`

Is there a way to see this change in the auth0 logs? If I look at the log entry for Successful Login, on the Action Details tab I see that the action was successful but I don’t see classlink\_tenant\_id in any of the data on the log entry.

edit: nm, I just switched testing from auth0 UI’s tester to my app so I could get the token and decode it to see

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 10, 2024, 7:42pm UTC](https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858/5 "2024-05-10T19:42:26Z")

</div>

Great! Glad that worked for you 🙂

---

<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:** [May 25, 2024, 3:33am UTC](https://community.auth0.com/t/i-need-help-converting-a-rule-to-action/133858/7 "2024-05-25T03:33:55Z")

</div>

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