Hello,
I’m new to using Auth0 and I’m having trouble adding custom claims. I’ve written a post-login rule in my authentication flow like this:
exports.onExecutePostLogin = async (event, api) => {
if (event.stats.logins_count === 1) {
const axios = require("axios")
// Définir les paramètres de la requête
const userData = {
firstName: event.user.user_metadata.user_firstname,
lastName: event.user.user_metadata.user_name,
email: event.user.email
}
// Faire la requête HTTP
try {
const response = await axios.post('https://-my-api-/api/User/', userData);
api.user.setUserMetadata("idUser", response.data);
api.idToken.setCustomClaim("https://-domain-/idUser", response.data.idUser)
} catch (error) {
console.error('Error during POST request:', error);
}
}
else {
api.idToken.setCustomClaim("https://-domain-/idUser", event.user.user_metadata.idUser)
}
};
Then, I’m trying to retrieve it in my Angular application like this:
this.authService.idTokenClaims$.subscribe(v => {
console.log(v)
})
However, the field doesn’t appear… I’m unable to retrieve it. Does anyone have any ideas on how to do it, please?