How to add custom data to a user according to his email

Is there a way to attach some data to a user after he logged in ?
I want to implement it somewhere after he press logged in and according to his credintials (email) it will find the applicable data to this user and pass it to me so inside the user object. |right now the user object holds :

  1. email:
  2. email_verified:
  3. family_name:
  4. given_name:
  5. locale:
  6. name:
  7. nickname:
  8. picture:
  9. sub:

how can i add to this object ?
Thanks in Advance!

Hi @Insighting,

Yes, you can use user_metadata or app_metadata to add information to the user’s profile.

In order to add the data to the user after they log in you should use a post login action. You can add the data as a custom claim. To set custom claims in actions you can use the following methods:

api.idToken.setCustomClaim
api.accessToken.setCustomClaim

Let me know if you have any questions.

Hi Dan,
Thank you for the quick response, I added some metaData manually via the “User Management” tab under “users” yet, I cannot see the metaData inside the user object I am getting after authenticating =>
const { user } = useAuth0();
I also tried this:

        const accessToken = await getAccessTokenSilently({
          audience: `https://${domain}/api/v2/`,
          // scope: "read:current_user",
        });

        const userDetailsByIdUrl = `https://${domain}/userinfo`;

        axios
          .get(userDetailsByIdUrl, {
            headers: {
              Authorization: `Bearer ${accessToken}`,
            },
          })
          .then((response) => {
            console.log(response.data);
          })
          .catch((error) => {
            console.log("ERROR API RESPONSE => ", error);
          });
      } catch (e) {
        console.log(e.message);
      }
    };

but I got the same exact user obect in response.

Where can i see the metaData?

In addition, why https://${domain}/userinfo; this request is getting through but any other request such as https://${domain}/api/v2/users returns 403 error

You will need to use a rule to add the metadata to the token. The user object in your application is being pulled directly from the token. Here is an example rule that adds some metadata to the token:

The userinfo endpoint is available from SPA applications with a user’s token, the management API endpoints are not.

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