I have tested your Auth0 Actions and it appears to be working as intended on my end.
I have set a test app metadata on the user and the action appears to fire as intended as seen in the images below:
exports.onExecutePostLogin = async (event, api) => {
const { test } = event.user.app_metadata;
if (event.authorization) {
api.idToken.setCustomClaim(`testing_data`, test);
}
};
You might not be setting the app metadata on the user in your implementation. Once the app metadata is set, does the user inside your Auth0 tenant reflect that as well?
In order to retrieve the custom claims that you have set for your user, you will need to use the getIdTokenClaims() when you are populating the user’s profile after authentication.
const claims = await getIdTokenClaims();
This function is available whenever you are using the useAuth0 hook for the React SDK.
You can review the following community post in regards to accessing User Metadata in React.
You can also read more about the functions available in the React SDK in our documentation.
Basically, once you have set the app metadata using an action, it should be available in the user object:
const { user } = useAuth0();
Alternatively, you should be able to access it via the loginWithRedirect() function as explained in this community post.
If you have any extra questions on the matter or if the resources provided above were not useful in resolving the issue, feel free to leave another reply on the post.
I am currently investigating the matter, could you please confirm that in the namespace of your custom claim that you are setting you do not use any Auth0 HTTP or HTTPS URL as a namespace identifier? These would be:
As mentioned in our documentation for Calling an API using React, these are needed so pass an access token to the API for your application to access private resources. That access token can be then accessed in the Profile component as seen in the example provided by our documentation.
Let me know if the following info and documentation is helpful regarding the matter.
By any chance, have you tried to validate your ID token using JWT.io as mentioned in this community post in order to inspect if the custom claims are added to it?
Please attempt to do so and let me know if the test claim is visible in there or not.
For the information that you have provided so far, you seem to be setting the action accordingly and when you try to retrieve the custom claims in your React App they should be definitely visible in your console log.
I will be looking further into the matter and will try to come back with an update as soon as possible.
Unfortunately, I was not able to replicate the issue that you are experiencing in viewing the custom claims set on the user.
In my integration with Auth0 and React, the token was successfully set on the user upon login and I could visualize the data on the profile page, in the console log and also when decoding the token as seen below:
I believe that the custom claim is not being set on the user, however, you implementation appears to be just fine.
Did you check if your action is being fired after a successful login? Can you also double check if you have deployed and assigned your action to a trigger?
Otherwise, I believe the only possible issue is that there might be some kind of misconfiguration with your integration, otherwise, the claim should be set on the IdToken just fine after the user completes the login process.
Also, having the fact that you are using refresh tokens for your integration that should not affect the outcome in any way.
If you have any other questions or additional info on the matter, leave another reply on the post.