Hi everyone,
I’ve searched extensively on this topic and found it brought up multiple times, but haven’t come across a clear solution.
I’m trying to set custom claims in the JWT idToken and accessToken using a Post Login Action in Auth0. Here’s what I’ve done so far:
- Created a Post Login Action with the following code:
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'namespace-preffix';
if (event.authorization) {
console.log(event.authorization.roles); // Successfully logs the roles
api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
}
};
- Bound the Action to the appropriate Post Login flow in the Triggers section.
Despite this setup:
- The roles are successfully logged in the Action Logs (
event.authorization.roles
logs correctly). - However, the custom claims never show up in the JWT idToken or accessToken.
I expect the custom claim (namespace/roles
) to appear in the token payload, but it’s consistently missing.
Has anyone encountered this issue or know of any steps I might be missing? Any guidance would be greatly appreciated!