# Manage custom field metadata

Udf is the abbreviation of User Defined Field (User Defined Field). Authing data entities (such as users, roles, groups, organizations, etc.) can add custom fields. You can configure fields that Authing does not come with by default. For example, if you need to create a school-related application, you can add a custom field. `school` field. At the same time, you can ask the user to supplement the information of this field after the user registration is completed. For detailed documentation, please see https://docs.authing.co/extensibility/user/extend-register-fields.html.

Please use the module in the following ways:

import {ManagementClient} from "authing-js-sdk"
const managementClient = new ManagementClient({
   userPoolId: "YOUR_USERPOOL_ID",
   secret: "YOUR_USERPOOL_SECRET",
})
managementClient.udf.list // Get a list of custom field metadata
managementClient.udf.set // Set custom fields
managementClient.udf.remove // ​​delete custom fields

# Set custom field metadata

UdfManagementClient().set(targetType, key, dataType, label)

Set custom field metadata, if the field does not exist, it will be created automatically.

# Parameters

  • targetType <UdfTargetType> Custom field target type, USER means user and ROLE means role.
  • key <string> field key
  • dataType <UdfDataType> data type, currently supports five data types. STRING is a character string, NUMBER is a number, DATETIME is a date, BOOLEAN is a boolean value, and OBJECT is an object.
  • label <string> The field Label is generally a Human Readable string.

# Example

import {ManagementClient, UdfTargetType, UdfDataType} from "authing-js-sdk"
const udf = await managementClient.udf.set(
 UdfTargetType.User,
 'school',
 UdfDataType.String,
 'school'
);
// If the custom field age does not exist, it will be created for the first time

import {ManagementClient, UdfTargetType, UdfDataType} from "authing-js-sdk"
const udf = await managementClient.udf.set(
   UdfTargetType.User,
   'age',
   UdfDataType.Number,
   'age'
);

// If the age field has been created before, the configuration of the field will be modified

const udf = await managementClient.udf.set(
   UdfTargetType.User,
   'age',
   UdfDataType.Number,
   'New description information'
);

# return value

  • Promise<UserDefinedField[]>

# Delete custom fields

UdfManagementClient().remove(targetType, key)

Delete custom fields

# Parameters

  • targetType <UdfTargetType> Custom field target type, USER means user and ROLE means role.
  • key <string> field key

# Example

await managementClient.udf.remove(UdfTargetType.User,'school');

# return value

  • Promise<UserDefinedField[]>

# Get custom field definition

UdfManagementClient().list(targetType)

Query custom fields defined by user pool

# Parameters

  • targetType <UdfTargetType> Custom field target type, USER means user and ROLE means role.

# Example

const list = await managementClient.udf.list(UdfTargetType.User);

# return value

  • Promise<UserDefinedField[]>