Lock.Android: Custom Fields at Signup

Lock.Android: Custom Fields at Signup

Lock.Android allows you to specify additional fields the user must complete before creating a new account. The extra fields will be shown on a second screen after the user completes the basic fields (email, username, password).

Create the Custom Fields

Create a new CustomField object passing all these 4 mandatory parameters.

  1. Icon: The int that points to the resource you want to use as Icon (keep it small).

  2. Type: The FieldType to use in this field. The type defines the keyboard layout and sometimes the input validation.

  3. Key: The String that identifies this value in the result JSON. It shouldn't be repeated! Repeated field keys will result in the second field getting removed from the list.

  4. Hint: The @StringRes of the text to show as hint in the field.

In addition, you can specify where the field is going to be stored on the user's profile. See the Storage section below for details.

You can also create fields that will not be shown to the user but can be used to include additional metadata in a dynamic way after sign up.

// Regular field
val nameField = CustomField(R.drawable.ic_name, FieldType.TYPE_NAME, "first_name", R.string.hint_first_name, CustomField.Storage.PROFILE_ROOT)

// Hidden field
val androidField = HiddenField("android_version", Build.VERSION.SDK_INT.toString(), Storage.USER_METADATA)

val customFields = listOf(nameField, androidField)

Was this helpful?

/

Repeat the above steps as many times as fields you need.

Use the Custom Fields

Pass the list of custom fields to the Lock instance while you are building it, using the method withSignUpFields().

val lock = Lock.newBuilder(auth0, callback)
              .withSignUpFields(customFields)
              //...
              .build(this)

Was this helpful?

/

If you have enabled sign up in the Application's Dashboard, users will be prompted to fill the remaining fields after they complete the basic fields (email/username, password) and hit Submit. The user must fill all of the custom fields before being able to complete the signup.

During sign up, the extra fields are attached to the user_metadata attribute or are directly set in the root user profile, depending on the Storage option chosen. You can access these properties by querying the user profile at any time, even from the Dashboard in the User's section.

Field Types

Each custom field can only have one FieldType associated.

  • TYPE_NAME

  • TYPE_NUMBER

  • TYPE_PHONE_NUMBER

  • TYPE_EMAIL

Storage

Each custom field can only have one Storage associated. You can choose to store it at the root level in a root profile attribute or inside the user_metadata attribute. To specify the storage location, use the five-parameter constructor and pass the Storage parameter of your choice. By default, fields will be stored inside the user_metadata attribute.

Available choices:

  • PROFILE_ROOT

  • USER_METADATA (default)

For the fields to be saved at the root level of the user's profile, their keys must match the ones listed in the endpoint documentation.