Auth0 App_metadata

Hi Auth0,

Still there is an issue when updating app_metadata
I am posting a sample code

 if (event.authorization) {
      const client_name = event.client.name;
      console.log(client_name);
       if (client_name === 'user_defined_a') {
        const productId = parseInt(event.user.app_product.id);
        const productName = event.user.app_product.name;
        const productUid = event.user.app_product.uid;
        productDescription = { value: productId, name: productName, uid: productUid };
        api.user.setAppMetadata(`${client_name}`, { "product_id": productId.toString(), "product_name": productName, "product_uid": productUid });
      } else if (client_name === 'user_defined_b') {
        const productId = parseInt(event.user.app_product.id);
        const productName = event.user.app_product.name;
        const productUid = event.user.app_product.uid;
        productDescription = { value: productId, name: productName, uid: productUid };
        api.user.setAppMetadata(`${client_name}`, { "product_id": productId.toString(), "product_name": productName, "product_uid": productUid });
      } else if (client_name === 'user_defined_c') {
        const productId = parseInt(event.user.app_product.id);
        const productName = event.user.app_product.name;
        const productUid = event.user.app_product.uid;
        productDescription = { value: productId, name: productName, uid: productUid };
        api.user.setAppMetadata(`${client_name}`, { "product_id": productId.toString(), "product_name": productName, "product_uid": productUid });
      } else {
           api.access.deny("Product information invalid access denied");
      }
      const email = event.user.user_metadata.user_email;
      const userId = event.user.user_metadata.user_id;
      const userTypeId = event.user.user_metadata.user_type_id;
      const userTypeName = event.user.user_metadata.user_type_name;
      const companyId = parseInt(event.user.user_metadata.company_id);

      api.accessToken.setCustomClaim(`${namespace}email`, email);
      api.user.setUserMetadata("user_email", email);
      if (typeof userId === "string") {
        api.accessToken.setCustomClaim(`${namespace}id`, userId);
        api.user.setUserMetadata("user_id", userId.toString());
      } else {
          api.access.deny("Identity invalid access denied");
      }
      if((typeof userTypeId === "number"&& typeof userTypeName === "string")) {
      const user_type_descr = { value: userTypeId, name: userTypeName };
      api.accessToken.setCustomClaim(`${namespace}type`, user_type_descr);
      api.user.setUserMetadata("user_type_name", userTypeName);
      api.user.setUserMetadata("user_type_id", userTypeId.toString());
      } else {
        api.access.deny("Identity invalid access denied");
      }
      if (typeof companyId === "number") {
        api.accessToken.setCustomClaim(`${namespace}companyId`, companyId);
        api.user.setUserMetadata("company_id", companyId);
      } else {
          api.access.deny("Identity invalid access denied");
      }
          api.accessToken.setCustomClaim(`${namespace}issuedFor`, productDescription);
          console.log("Access Token");
 } 

Note:

client “user_defined_a” connects to database A
client “user_defined_b and user_defined_c” connects to database B

Issue:
(Everything works fine)

When i login using client “user_defined_a” app_metadata is set
When i login using client “user_defined_b” and “user_defined_c” appropriate app_metadata is appended.

But (Issues)
When i login using client “user_defined_b” and “user_defined_c” appropriate app_metadata is set
The issue is when i login using client “user_defined_a” app_metadata is not appended to the existing app_metadata

Use case:

I have multiple application using auth0.
Each client is connected to different custom database connection in auth0.
Each client will return a unique set of information (unique productId, productUid, productName)
There is only 1 post login action.
Some clients are M2M and some are SPA

Can you let me know why the above issue is happening or any tips to solve this issue

Regards,
Walter

There is also something fishy happening/ or my lack of understanding of the info displayed in the Users section of auth0

After login in to three different application (both M2M and SPA)
I went to User Management → Users → and clicked the user info → app_metadata
i see the following info

{
“user_defined_b”: {
“product_id”: “2”,
“product_name”: “b”,
“product_uid”: “b”
},
“user_defined_c”: {
“product_id”: “2”,
“product_name”: “c”,
“product_uid”: “c”
}
}

And when i print the app_metadata info
console.log(“…”,event.user.app_metadata);
in post login action i see exact info which i saw in User Management → Users → and clicked the user info → app_metadata

But,

When i login to application which is connected to client user_defined_a,
The user_defined_a info is not appended to the app_metadata but in the console.log in post login action script i am getting the correct info.
console.log(“…”,event.user.app_metadata);

I believe event.user.app_metadata gives the stored information, but this is not reflected in User Management → Users → and clicked the user info → app_metadata

Hi @walter.adbe,

I understand that you’re having trouble setting the app_metadata using a Post Login Action.

Can you help me clarify if your application “user_defined_a” is an M2M app? And that applications “user_defined_b” and “user_defined_c” are SPAs?

Any help would be appreciated. Am i doing this correctly or is there a better way to achieve what i am trying to do