Setting a Null Value to an Attribute Causes the Management API to Execute in Auth0 Actions
Setting an attribute to null in an Auth0 Action triggers the Management API, leading to unexpected usage. This occurs because setting a null value is an exception to the built-in metadata update functions that normally prevent internal Management API calls when setting an identical value.
The following built-in metadata update functions do not trigger an internal Management API call when setting the same value.
api.user.setAppMetadata("item-1", "acme")
api.user.setUserMetadata("item-2", "user")
Setting a null value for an attribute is an exception and causes the Management API to execute every time.
// These calls execute the management API every time
api.user.setAppMetadata("item-1", null)
api.user.setUserMetadata("item-2", null)- Actions
- setAppMetadata
- setUserMetadata
Setting a null value is an exception in the built-in metadata update functions, which normally prevent internal Management API calls when setting an identical value.
How is the unnecessary Management API execution prevented?
To avoid unnecessary Management API calls, implement an if statement to verify the attribute value before setting it to null.
// Only set the attribute to null if its' value isn't null
if (api.user.app_metadata["item-1"] != null) {
api.user.setAppMetadata("item-1", null);
}
if (api.user.user_metadata["item-2"] != null) {
api.user.setAppMetadata("item-2", null);
}