How to add custom claim to access token

Ready to post? :mag: First, try searching for your answer.
I have created action like this

exports.onExecutePostLogin = async (event, api) => {
if (event.authorization) {
const id = event.user.user_id;
api.accessToken.setCustomClaim(‘tl_id’, id);
}
};

But when I request accessToken like this I can’t see tl_id in my accessToken

export const getAuth0ManagementApiToken = async () => {
const options = {
method: “POST”,
url: ${process.env.AUTH0_ISSUER_BASE_URL}/oauth/token,
headers: { “content-type”: “application/x-www-form-urlencoded” },
data: new URLSearchParams({
grant_type: “client_credentials”,
client_id: process.env.AUTH0_CLIENT_ID ?? “”,
client_secret: process.env.AUTH0_CLIENT_SECRET ?? “”,
audience: ${process.env.AUTH0_ISSUER_BASE_URL}/api/v2/,
}),
};

const req = await axios.request(options);

return req.data;
};

The reason you are not seeing the custom claim is that it looks like you created an Auth0 action in the Post Login trigger, but you are requesting the token using Client Credential flow.

If you need custom claims during the Client Credentials flow, you should create an action in the Credential Exchange trigger (for Machine to Machine\Client Credential flow).

If you need custom claims after login (i.e., for the Access token after login), you should use the Post Login trigger.