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

# ユーザー登録前フロー

> ユーザーがデータベースまたはパスワードレス接続を通じて登録を試みる際に作動するユーザー登録前フローについて説明します。メタデータが作成される、または登録を拒否する前にユーザープロファイルに追加するために使用されます。

ユーザー登録前フローは、ユーザーがデータベース、またはパスワードレス接続に追加される前に実行されます。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/ja-jp/cdy7uua7fh8z/2KtUcZhaBcT12GxjhBJZFG/a29883931efed0618078db632cc77017/pre-user-registration-flow.png" alt="アクションのユーザー登録前フローを示す図。" />
</Frame>

このフロー内のアクションはブロッキング（同期的）であり、トリガーのプロセスの一部として実行されます。そのため、アクションが完了するまでAuth0パイプラインの他の部分の実行が停止されます。

## トリガー

### Pre User Registration（ユーザー登録前）

`pre-user-registration`トリガーは、ユーザーがデータベースまたはパスワードレス接続を通して、登録を試みる際に実行されます。このトリガーは、メタデータが作成される、またはカスタムロジックを使用した登録を拒否する前にユーザープロファイルに追加される際に使用されます。

<Warning>
  現在のところ、`pre-user-registration`アクションを使用して、パスワードレスユーザーにメタデータを追加することはできません。
</Warning>

#### リファレンス

* [イベントオブジェクト](/docs/ja-jp/customize/actions/explore-triggers/signup-and-login-triggers/pre-user-registration-trigger/pre-user-registration-event-object)：新しいユーザーを登録するための要求についてのコンテキスト情報を提供します。
* [APIオブジェクト](/docs/ja-jp/customize/actions/explore-triggers/signup-and-login-triggers/pre-user-registration-trigger/pre-user-registration-api-object)：フローの動作を変更するためのメソッドが提供されます。

## 一般的なユースケース

### 位置で登録を拒否する

pre-user-registrationのアクションは、ユーザーのサインアップを防ぐために使用されます。

```javascript lines theme={null}
/**
 * @param {Event} event - Details about registration event.
 * @param {PreUserRegistrationAPI} api
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  if (event.request.geoip.continentCode === "NA") {

    // localize the error message 
    const LOCALIZED_MESSAGES = {
      en: 'You are not allowed to register.',
      es: 'No tienes permitido registrarte.'
    };

    const userMessage = LOCALIZED_MESSAGES[event.request.language] || LOCALIZED_MESSAGES['en'];
    api.access.deny('no_signups_from_north_america', userMessage);
  }
};
```

### メタデータをユーザープロファイルに設定する

pre-user-registrationのアクションは、作成される前にメタデータをユーザープロファイルに追加するために使用することができます。

<Warning>
  現在のところ、`pre-user-registration`アクションを使用して、パスワードレスユーザーにメタデータを追加することはできません。
</Warning>

```javascript lines theme={null}
/**
 * @param {Event} event - Details about registration event.
 * @param {PreUserRegistrationAPI} api
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  api.user.setUserMetadata("screen_name", "username");  
};
```

### ユーザープロファイルに、別のシステムからのユーザーIDを保存する

pre-user-registrationのアクションはユーザープロファイルに、別のシステムからのユーザーIDを保存するために使用することができます。

```javascript lines theme={null}
const axios = require('axios');

const REQUEST_TIMEOUT = 2000; // Example timeout

/**
* Handler that will be called during the execution of a PreUserRegistration flow.
*
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
exports.onExecutePreUserRegistration = async (event, api) => {
  try {
    // Set a secret USER_SERVICE_URL = 'https://yourservice.com'
    const remoteUser = await axios.get(event.secrets.USER_SERVICE_URL, {
      timeout: REQUEST_TIMEOUT,
      params: {
        email: event.user.email 
      }
    });

    if (remoteUser) {
      api.user.setAppMetadata('my-api-user-id', remoteUser.id); 
    }
  } catch (err) {
    api.validation.error('custom_error', 'Custom Error');
  }
};
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  `axios`などの`npm`ライブラリーを使用する場合は、そのライブラリーをアクションに依存関係として追加しなければなりません。詳細については、「[初めてアクションを作成する](/docs/ja-jp/customize/actions/write-your-first-action)」の「依存関係を追加する」セクションをお読みください。
</Callout>
