# How to incorporate roles in the useUser hook from nextjs-auth0?

**URL:** <https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361>\
**Category:** Get Help\
**Tags:** rbac, nextjs\
**Created:** [October 13, 2022, 5:32pm UTC](https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361 "2022-10-13T17:32:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![faabiopk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/faabiopk/32/40579_2.png) [@faabiopk](https://community.auth0.com/u/faabiopk)\
**Post date:** [October 13, 2022, 5:32pm UTC](https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361/1 "2022-10-13T17:32:14Z")

</div>

> Please include the following information in your post:
> 
> - Which SDK this is regarding: [nextjs-auth0](https://github.com/auth0/nextjs-auth0)
> - SDK Version: 1.9.1
> - Platform Version: N/A
> - Code Snippets/Error Messages/Supporting Details/Screenshots:  
> ![Untitled-1](https://global.discourse-cdn.com/auth0/original/3X/b/d/bddb92f94b6e671498be549a9bdedef7f72d1b06.jpeg)

Hi,

I am struggling a bit with the process of using roles and permissions with auth0 . The desired outcome would be to have my roles and/or permissions added to my user on the `useUser()` hook from the `nextjs-auth0` library.

Right now,

- I have an API with RBAC enabled;
- Created roles and permissions;
- Assigned a role to my user;
- Connected the APIs to each other;
- And created this Login flow

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https:// __________.auth0.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
  }
};

```

But it does not show up when using getting my user. I created a “dummy” Login flow which adds the `foobar: foobar2` bit that shows on my screenshot (`...setCustomClaim("foobar", "foobar2")`). I am not sure what I am missing here. The goal is to have the roles and permission to conditional rendering UI elements and afterword inside `pages/api` for proctecting certain actions.

Am I missing an important step?

Thanks.

---

<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:** [October 14, 2022, 1:01am UTC](https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361/3 "2022-10-14T01:01:44Z")

</div>

Hey there @faabiopk welcome to the community!

Most of what you’ve described seems correct so that’s good 🙂 I don’t think the namespace you’ve used (`auth0.com`) will work per the guidelines [here](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines). Are you able to test using a different namespace or a non-namespaced value instead?

I also recommend checking out this post with regards to permissions:

> [@Retrieve user roles and permission on profile with nextjs](https://community.auth0.com/t/retrieve-user-roles-and-permission-on-profile-with-nextjs/92070/3):
>
> hey @barekliton welcome to the community! You’ll need to explicitly add the roles to ID Tokens using an Action as outlined in the following FAQ: [https://community.auth0.com/t/how-to-add-roles-and-permissions-to-the-id-token-using-actions/84506](https://community.auth0.com/t/how-to-add-roles-and-permissions-to-the-id-token-using-actions/84506) Permissions are a bit different, and are typically kept within the context of an access token. I recommend taking a look at [RBAC](https://auth0.com/docs/manage-users/access-control/rbac) as this provides you with the option (assuming you have an API registered in Auth0) to automatically add permissions to user…

Hope this helps!

---

<div class="post-metadata">

**Author:** ![faabiopk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/faabiopk/32/40579_2.png) [@faabiopk](https://community.auth0.com/u/faabiopk)\
**Post date:** [October 14, 2022, 1:08am UTC](https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361/4 "2022-10-14T01:08:49Z")

</div>

Thanks! That was it.

I was using my AUTH0\_ISSUER\_BASE\_URL as the namespace. I thought it was something arbitrary, but changing to something else did the trick.

Thanks a lot for the quick response.

---

<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:** [October 14, 2022, 5:09pm UTC](https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361/5 "2022-10-14T17:09:53Z")

</div>

Awesome, good to know!

---

<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:** [October 28, 2022, 5:10pm UTC](https://community.auth0.com/t/how-to-incorporate-roles-in-the-useuser-hook-from-nextjs-auth0/92361/6 "2022-10-28T17:10:08Z")

</div>

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