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