# How to detect changes in Access Token (added via Rules)

**URL:** <https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430>\
**Category:** Get Help\
**Tags:** api, auth0, login\
**Created:** [March 23, 2022, 10:32pm UTC](https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430 "2022-03-23T22:32:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sympi](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@sympi](https://community.auth0.com/u/sympi)\
**Post date:** [March 23, 2022, 10:32pm UTC](https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430/1 "2022-03-23T22:32:57Z")

</div>

I am renewing Access Token once it expires (8 hours in my case).

The problem is that I save some things in Access Token. Using Rules I am adding “roles” to it like this:

```auto
  context.accessToken[namespace + '/roles'] = context.authorization.roles;

```

This way, in my app I can display appropriate UI based on the role the user has, which is great.

The problem is that once I add/delete a role to the user, they have to sign out and sign in again to regenerate a new access token so that the UI gets updated.

Is there a way to detect changes to the data added using rules and based on that sign out user or regenerate a new access token?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 23, 2022, 11:18pm UTC](https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430/3 "2022-03-23T23:18:36Z")

</div>

Hi @sympi,

Thanks for reaching out to the Auth0 Community!

> [@sympi](#):
>
> The problem is that once I add/delete a role to the user, they have to sign out and sign in again to regenerate a new access token so that the UI gets updated.

Before we proceed, could you please clarify how you are adding and deleting the user’s Roles?

And could you please clarify if you are changing them after the user has logged in?

Thank you.

---

<div class="post-metadata">

**Author:** ![sympi](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@sympi](https://community.auth0.com/u/sympi)\
**Post date:** [March 24, 2022, 7:40am UTC](https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430/4 "2022-03-24T07:40:24Z")

</div>

Hi @rueben.tiow 🙂

> And could you please clarify if you are changing them after the user has logged in?

Yes, I can change them at any point in time, even if user is already logged in.

> Before we proceed, could you please clarify how you are adding and deleting the user’s Roles?

I do it through Dashboard → Users → User → Roles → here I can remove or assign a role

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 24, 2022, 10:57pm UTC](https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430/5 "2022-03-24T22:57:18Z")

</div>

Hi @sympi,

Thank you for your response and clarification.

Generally, when updating a user before they log in, the user profile information should reflect correctly after the login transaction is complete. This is expected when decoding the access token of the user.

On the contrary, when updating a user post login, the user profile information will not reflect the newly updated information since the decoded token holds information up until the login transaction.

As you observed, you will need to refresh the access tokens to read the newly updated user profile details.

There are a couple of options.

1. [Configure Silent Authentication](https://auth0.com/docs/authenticate/login/configure-silent-authentication) to leverage the use of refresh tokens in getting a new access token without prompting the user for credentials again or having them log out and log in again.

or

1. Calling the [Management API Get a User endpoint](https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id) to get the latest user profile.

By doing so, you can guarantee the latest user profile data.

I hope that helps!

Please let me know if you need further clarification or have any questions.

Thank you.

---

<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 22, 2022, 9:02am UTC](https://community.auth0.com/t/how-to-detect-changes-in-access-token-added-via-rules/80430/6 "2022-12-22T09:02:39Z")

</div>


