I can't get my custom claim in my idToken

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 => {

However, the field doesn’t appear… I’m unable to retrieve it. Does anyone have any ideas on how to do it, please?

Hey there!

We are nearing the support of Rule in our stack so I would encourage you to utilise Actions. Here’s a step by step tutorial on how to use Actions to add custom claims to ID Token:

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