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

# Pre User Registration

> ユーザーが Database または Passwordless 接続に追加される前に実行される Pre User Registration Actions について説明します。ユーザープロファイルの作成前にメタデータを追加したり、登録を拒否したりできます。

`pre-user-registration` トリガーは、ユーザーが作成される前に、Database または <Tooltip tip="Passwordless: 最初の認証要素としてパスワードを使用しない認証方式です。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Passwordless">Passwordless</Tooltip> 接続を通じて登録しようとすると実行されます。このトリガーを使用して、ユーザープロファイルの作成前にメタデータを追加したり、カスタムロジックで登録を拒否したりできます。

<Frame>
  <img src="https://mintcdn.com/translations/Dcx0M11uuptU53TX/docs/images/cdy7uua7fh8z/2KtUcZhaBcT12GxjhBJZFG/9633b4454ac1c06c0deed6c97e70fe7d/pre-user-registration-flow.png?fit=max&auto=format&n=Dcx0M11uuptU53TX&q=85&s=f086c5deb8fb184c3097b6a97046a5da" alt="Actions の Pre User Registration フローを示す図。" width="849" height="286" data-path="docs/images/cdy7uua7fh8z/2KtUcZhaBcT12GxjhBJZFG/9633b4454ac1c06c0deed6c97e70fe7d/pre-user-registration-flow.png" />
</Frame>

このフローの Actions はブロッキング (同期) であり、トリガーの処理の一部として実行されます。Action が完了するまで、Auth0 pipeline の後続の処理は実行されません。

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

<div id="references">
  ## 参照
</div>

* [イベントオブジェクト](/docs/ja-jp/customize/actions/reference/pre-user-registration/pre-user-registration-event-object): 新規ユーザー登録リクエストに関するコンテキスト情報を提供します。
* [APIオブジェクト](/docs/ja-jp/customize/actions/reference/pre-user-registration/pre-user-registration-api-object): フローの動作を変更するためのメソッドを提供します。

<div id="common-use-cases">
  ## 一般的なユースケース
</div>

<div id="deny-registration-by-location">
  ### 場所に基づいて登録を拒否する
</div>

pre-user-registration Action を使用すると、ユーザーのサインアップを防止できます。

```javascript lines theme={null}
/**
 * @param {Event} event - 登録しようとしているユーザーとコンテキストに関する詳細。
 * @param {PreUserRegistrationAPI} api - サインアップの動作を変更するためのメソッドを提供するインターフェース。
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  if (event.request.geoip.continentCode === "NA") {

    // エラーメッセージをローカライズする 
    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);
  }
};
```

<div id="set-metadata-in-the-user-profile">
  ### ユーザープロファイルにメタデータを設定する
</div>

pre-user-registration Action を使用すると、ユーザープロファイルの作成前にメタデータを追加できます。

```javascript lines theme={null}
/**
 * @param {Event} event - 登録を試みているユーザーとコンテキストに関する詳細。
 * @param {PreUserRegistrationAPI} api - サインアップ の動作を変更するためのメソッドを提供するインターフェース。
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  api.user.setUserMetadata("screen_name", "username");
};
```

<div id="store-a-user-id-from-another-system-in-the-user-profile">
  ### 別のシステムのユーザー ID をユーザープロファイルに保存する
</div>

pre-user-registration Action を使用すると、別のシステムのユーザー ID をユーザープロファイルに保存できます。

```javascript lines expandable theme={null}
const axios = require('axios');

const REQUEST_TIMEOUT = 2000; // タイムアウトの例

/**
 * @param {Event} event - 登録を試みているユーザーとコンテキストに関する詳細。
 * @param {PreUserRegistrationAPI} api - サインアップの動作を変更するためのメソッドを備えたインターフェース。
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  try {
    // シークレット 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` ライブラリを使用するには、そのライブラリを依存関係として Action に追加する必要があります。詳細については、[Write Your First Action](/docs/ja-jp/customize/actions/write-your-first-action) の「依存関係を追加する」セクションを参照してください。
</Callout>

<div id="deny-access-to-specific-ja3ja4-fingerprints">
  ### 特定のJA3/JA4フィンガープリントからのアクセスを拒否する
</div>

`event.security_context` オブジェクトには、現在のトランザクションのJA3/JA4フィンガープリント値が含まれています：

```javascript lines theme={null}
/**
 * @param {Event} event - 登録しようとしているユーザーとコンテキストに関する詳細。
 * @param {PreUserRegistrationAPI} api - サインアップ の動作を変更するためのメソッドを提供するインターフェース。
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  const clientJa4 = event?.security_context?.ja4;
  console.log('[ACTION]', {clientJa4});
  const badFingerprints = ['t13d1517h2_8daaf6152771_b6f405a00624','t13d1516h2_8daaf6152771_d8a2da3f94cd'];
  if (clientJa4 && badFingerprints.includes(clientJa4)){
    api.access.deny('suspicious_tls_fingerprint', 'Your TLS fingerprint has been flagged as suspicious');
  }
};
```
