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