> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/llms.txt
> Use this file to discover all available pages before exploring further.

# サインアッププロンプトのカスタマイズが収集したエンドユーザーデータの検証と保管にアクションを使用する (1)

> エンドユーザーのデータの検証と保管にAuth0 Actionsを使用する方法について説明します。

[サインアッププロンプトのカスタマイズ](/docs/ja-jp/customize/login-pages/universal-login/customize-signup-and-login-prompts)で`pre-user-registration`（ユーザー登録前）トリガーを使用すると、サインアッププロンプトでエンドユーザーが提供したデータ（ユーザーの電話番号や位置情報など）を`user_metadata`に追加することができます。このデータを任意で検証して、プロンプトに検証エラーを表示することもできます。

### 前提条件

* テナントに検証済の[カスタムドメイン](/docs/ja-jp/customize/custom-domains)がある
* テナントに[ページテンプレート](/docs/ja-jp/customize/login-pages/universal-login/customize-templates)が設定されている

### サインアッププロンプトにフィールドを追加する

[入力ポイント](https://auth0.com/docs/sign-up-prompt-customizations#-signup-prompt-entry-points)を使ってプロンプトにカスタムフィールドを挿入するには、[Management API](https://auth0.com/docs/api/management/v2/prompts/put-custom-text-by-language)を使用します。この例では、以下のコンテンツを`ulp-container-form-content-start`の挿入ポイントに追加します。

```lines theme={null}
<div class="ulp-field">
  <label for="first-name">First Name</label>
  <input type="text" name="ulp-first-name" id="first-name">
</div>
```

その結果、サインアッププロンプトに［First Name（名）］セクションが含まれます。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/580LNGMxSkRlazJEdcVNpn/5fa98d4b414ac2133d1d6f4e327cea5a/Screenshot_2023-10-05_at_4.07.38_PM.png" alt="" />
</Frame>

### ユーザー登録前トリガーにアクションを作成する

カスタムのpre-user registration（ユーザー登録前）アクションを構築するには、[**［Actions（アクション）］ > ［Library（ライブラリー）］ > ［Build Custom（カスタムの構築）］** ](https://manage.auth0.com/dashboard/us/dev-6endizjt/actions/library)**に移動します。**

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/52VSznphe2TyoJQnAn4nQg/ba5d8a7fc8ad23f8cbb528d78ffb36ba/Create_Action_-_JP.png" alt="" />
</Frame>

コードエディターで、以下のように`onExecutePreUserRegistration`ハンドラーを更新します。

```lines theme={null}
exports.onExecutePreUserRegistration = async (event, api) => {
  const firstName = event.request.body['ulp-first-name'];
  api.user.setUserMetadata("firstName", firstName);
};
```

ユーザー入力を任意で検証し、`api.validation.error`を呼び出して検証エラーを送信してから、アクションをデプロイすることもできます。

```lines theme={null}
exports.onExecutePreUserRegistration = async (event, api) => {
  const firstName = event.request.body['ulp-first-name'];
  if(!firstName) {
    api.validation.error("invalid_payload", "Missing first name");
    return;
  }

  api.user.setUserMetadata("firstName", firstName);
};
```

### フローにアクションを追加する

[**［Actions（アクション）］ > ［Flows（フロー）］ > ［Pre User Registration（ユーザー登録前）］ > ［Add Action（アクションの追加）］ > ［Custom（カスタム）］**](https://manage.auth0.com/dashboard/us/dev-6endizjt/actions/flows/pre-user-signup/)に移動し、新しいアクションを登録フローにドラッグ&ドロップしてから、**［Apply（適用）］** を選択します。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/5JmjwcdZCX7pDukNa90cgD/dae853b10cf4c41d2d3543a8e167aae7/3333.png" alt="" />
</Frame>

### アクションをテストする

テストフローでアカウントにサインアップして、**［First Name（名）］** フィールドを空のままにします。送信すると、エラーが表示されます。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/7qIWCsP8doFWPJGvMTNXJY/1225f9b3ff7ac01a7e9b59f03ca5e139/2024-01-31_16-10-10.png" alt="" />
</Frame>

**［First Name（名）］** フィールドに名前を入力すると、送信が成功します。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/6TaK1VQyKGELMGmhuRIbVA/b453fe2eb97c95d92e4fbd68ce3cbd6a/2024-01-31_16-12-01.png" alt="" />
</Frame>

### user\_metadataにデータが保存されたことを確認する

[**［User Management（ユーザー管理）］ > ［Users（ユーザー）］** ](https://manage.auth0.com/dashboard/us/dev-6endizjt/users)に移動し、［Details（詳細）］タブでデータが保存されていることを確認します。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/3x5lyrSJJgJQhbjsxoTmG6/a68145ab865c02b8b9331faac4fbdf0b/User_Metadata_-_Japanese.png" alt="" />
</Frame>
