Custom claims not added to tokens in post-login Action flow

I am using actions to add custom claims on a post-login flow. I’ve added the Action to the flow. When I check the tokens (id or access, same problem) they do not have the custom claims. They only have iss, sub, aud (which is an array), iat, exp, azp, and scope.

Here is my Action:
exports.onExecutePostLogin = async (event, api) => {
console.log(‘Adding claim…’)
api.accessToken.setCustomClaim(‘https://myrandomclaims.com/testclaim1’,'test1’)
api.idToken.setCustomClaim(‘https://myrandomclaims.com/testclaim2’,'test2’)
}

Hi @joecanada,

Welcome to the Auth0 Community!

Could you try using this Post-login template and customizing to your needs and seeing if this resolves your issue?

You can test the Action on its own by pressing the “Test” button and then pressing the “Run” button.

Having tested this myself, I was able to get the Action working as intended.

Thank you. Not sure what was wrong but I got it working. I think it was failing silently on some other portion of my code in the action, then it was defaulting back to the basic token with no custom claims.

Hey @joecanada,

That’s great to hear!

Please let me know if you have any further questions. I’d be happy to help.

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