Hi @walter.adbe,
Thanks for reaching out to the Auth0 Community!
It appears that the way you have written your Post-Login Action script to append user_metadata and app_metadata properties to the access token, does not consider the condition where the user is authenticating against the SPA or M2M.
Consider using a conditional statement to check which app the user is authenticating against when appending custom claims. For example:
exports.onExecutePostLogin = async (event, api) => {
const namespace = "http://yourNamespace/";
if(event.authorization){
if(event.client.name === 'SPA'){
api.accessToken.setCustomClaim(`${namespace}user_metadata`, event.user.user_metadata)
api.accessToken.setCustomClaim(`${namespace}app_metadata`, event.user.app_metadata)
} else if (event.client.name === 'M2M'){
api.accessToken.setCustomClaim(`${namespace}user_metadata`, event.user.user_metadata)
api.accessToken.setCustomClaim(`${namespace}app_metadata`, event.user.app_metadata)
}
}
};
Doing it this way will only append custom claims based on the application the user logs into.
Please let me know if you have any questions.
Thanks,
Rueben