# Access role from SPA

**URL:** <https://community.auth0.com/t/access-role-from-spa/126403>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [February 2, 2024, 6:14pm UTC](https://community.auth0.com/t/access-role-from-spa/126403 "2024-02-02T18:14:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giom](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Giom](https://community.auth0.com/u/Giom)\
**Post date:** [February 2, 2024, 6:14pm UTC](https://community.auth0.com/t/access-role-from-spa/126403/1 "2024-02-02T18:14:36Z")

</div>

Hi everyone, I’m new to Auth0.  
I want to access user’s role from a React SPA, simply to display it beside it’s name.  
I’m currently using the example React SPA available here [auth0-react-samples/Sample-01 at master · auth0-samples/auth0-react-samples · GitHub](https://github.com/auth0-samples/auth0-react-samples/tree/master/Sample-01)

I added the below action as PostLogin Action

```auto
exports.onExecutePostLogin = async (event, api) => {
    // This action adds the authenticated user's email address to the access token.
    var roles = event.authorization?.roles || ['TEST'];
    if (roles) {
        api.user.setAppMetadata("roles", roles);
    }
};

```

However, I don’t know how to access AppMetaData either…

Could you help me ?

---

<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:** [February 2, 2024, 7:27pm UTC](https://community.auth0.com/t/access-role-from-spa/126403/3 "2024-02-02T19:27:56Z")

</div>

Hi @Giom,

Welcome to the Auth0 Community!

You could add the user’s roles as a custom claim to the access token so that you can use that information when a user logs in to display their role.

[https://community.auth0.com/t/adding-custom-claims-to-tokens/84590](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590)

Let me know if you have any questions.

Thanks,  
Rueben

---

<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:** [February 16, 2024, 7:28pm UTC](https://community.auth0.com/t/access-role-from-spa/126403/4 "2024-02-16T19:28:15Z")

</div>

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