# Display button for a specific role

**URL:** <https://community.auth0.com/t/display-button-for-a-specific-role/60151>\
**Category:** Get Help\
**Created:** [March 26, 2021, 9:49pm UTC](https://community.auth0.com/t/display-button-for-a-specific-role/60151 "2021-03-26T21:49:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![k-auth0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/k-auth0/32/18365_2.png) [@k-auth0](https://community.auth0.com/u/k-auth0)\
**Post date:** [March 26, 2021, 9:49pm UTC](https://community.auth0.com/t/display-button-for-a-specific-role/60151/1 "2021-03-26T21:49:21Z")

</div>

Hello Auth0 Team

Can you update the below example to demonstrate - usage of roles

> **[The Complete Guide to Angular User Authentication with Auth0](https://auth0.com/blog/complete-guide-to-angular-user-authentication/?_ga=2.82584657.612154162.1616452206-1127333818.1604614240)**
>
> Learn how to add user authentication to Angular using Observables and HTTP Interceptors. Learn the core concepts of Angular authenticatio...

Scenario: Show External Link only if role is admin or something like that

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 29, 2021, 2:12pm UTC](https://community.auth0.com/t/display-button-for-a-specific-role/60151/3 "2021-03-29T14:12:23Z")

</div>

Hi @k-auth0,

I’m happy to pass on that feedback!

You should be able to conditionally render a button based on role by:

1. Add the role to the ID Token:

```auto
function (user, context, callback) {
  const namespace = 'http://demozero.net';
  const assignedRoles = (context.authorization || {}).roles;

  let idTokenClaims = context.idToken || {};
  let accessTokenClaims = context.accessToken || {};

  idTokenClaims[`${namespace}/roles`] = assignedRoles;
  accessTokenClaims[`${namespace}/roles`] = assignedRoles;

  context.idToken = idTokenClaims;
  context.accessToken = accessTokenClaims;

  callback(null, user, context);
}

```

1. check for the role when rendering the button (here’s an example from altering the [Angular Quickstart](https://auth0.com/docs/quickstart/spa/angular/01-login) `src/app/components/nav-bar/nav-bar.component.html`):

```auto
          <!-- Fullsize dropdown: show if authenticated -->
          <li
            class="nav-item dropdown"
            *ngIf="auth.user$ | async as user"
            ngbDropdown
          >
            <a
              ngbDropdownToggle
              class="nav-link dropdown-toggle"
              id="profileDropDown"
              data-toggle="dropdown"
            >
              <!-- Profile image should be set to the profile picture from the id token -->
              <img
                [src]="user.picture"
                alt="Profile picture"
                class="nav-user-profile rounded-circle"
                style="width: 75px;"
              />
            </a>
            <div class="dropdown-menu dropdown-menu-left" ngbDropdownMenu>
              <!-- Show the user's full name from the id token here -->
              <div class="dropdown-header">
                {{ user.name }}
              </div>
              <a routerLink="/profile" class="dropdown-item dropdown-profile">
                <fa-icon [icon]="faUser" class="mr-3"></fa-icon> Profile
              </a>
              <button
                (click)="logout()"
                class="btn btn-link dropdown-item"
                id="qsLogoutBtn"
              >
                <fa-icon [icon]="faPowerOff" class="mr-3"></fa-icon> Log out
              </button>
              <!-- Conditional button in nav if the user has the role "admin" -->
              <button
                class="btn btn-primary btn-block"
                id="qsLoginBtn"
                *ngIf="user['http://demozero.net/roles'].includes('admin')"
                (click)="loginWithRedirect()"
              >
                Conditional button
              </button>

            </div>
          </li>

```

---

<div class="post-metadata">

**Author:** ![k-auth0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/k-auth0/32/18365_2.png) [@k-auth0](https://community.auth0.com/u/k-auth0)\
**Post date:** [March 30, 2021, 9:31pm UTC](https://community.auth0.com/t/display-button-for-a-specific-role/60151/4 "2021-03-30T21:31:08Z")

</div>

> [@stephanie.chamblee](#):
>
> Add the role to the ID Token:

I presume this goes in Rules inside Auth0?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 30, 2021, 10:04pm UTC](https://community.auth0.com/t/display-button-for-a-specific-role/60151/5 "2021-03-30T22:04:10Z")

</div>

Yes, that is correct! This is the code for a rule in your Auth0 tenant:

```auto
function (user, context, callback) {
  const namespace = 'http://demozero.net';
  const assignedRoles = (context.authorization || {}).roles;

  let idTokenClaims = context.idToken || {};
  let accessTokenClaims = context.accessToken || {};

  idTokenClaims[`${namespace}/roles`] = assignedRoles;
  accessTokenClaims[`${namespace}/roles`] = assignedRoles;

  context.idToken = idTokenClaims;
  context.accessToken = accessTokenClaims;

  callback(null, user, context);
}

```

---

<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:** [April 14, 2021, 10:04pm UTC](https://community.auth0.com/t/display-button-for-a-specific-role/60151/6 "2021-04-14T22:04:47Z")

</div>

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