melek
1
I’m trying to add roles as a custom claim in user’s idToken. I’m running the following post-login action.
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://my-app.example.com';
if (event.authorization) {
api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
}
}
I’m checking for it like this on my dashboard component.
const { user, isLoading, error} = useUser();
if (user){
console.log(user['https://my-app.example.com/roles'])
}
It’s returning undefined.
Hi @melek
Welcome to the Auth0 Community!
I have attempted to reproduce the issue on my end however everything works as expected.
This is the console log in my application:

And this is the claim inside the token:
I would recommend you to review our documentation regarding creating custom claims and to check if you are respecting our namespace guidelines.
If you have any other questions, feel free to leave a reply!
Kind Regards,
Nik
melek
4
Hi @nik.baleca,
I don’t think the issue is with the namespace as I’m using the exact same namespace https://my-app.example.com/
I see
Could you let me know what SDK/Sample app are you using?
Kind Regards,
Nik
melek
6
I’m using version auth0 v4.1.0 with next js v15.2.1
Hi again.
By any chance, if you log the claim outside of the if statement, does it work?
Does your user have assigned roles to it inside the Auth0 Dashboard?
After some testing, I still could not reproduce the issue on my end.
I can recommend to log the user to see if the roles are being mapped to the custom claim, however, if you try the following:
console.log(user["https://my-app.example.com/roles"])
or
const key = "https://my-app.example.com/roles"
console.log(user[key])
Both of these should return the same value of the custom claim that you have set inside the action.
If you have any other questions on the matter, let me know.
Kind Regards,
Nik