ユーザー登録前フロー

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

アクションのユーザー登録前フローを示す図。

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

トリガー

Pre User Registration(ユーザー登録前)

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

リファレンス

一般的なユースケース

位置で登録を拒否する

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

/**
 * @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);
  }
};

Was this helpful?

/

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

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

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

Was this helpful?

/

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

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

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');
  }
};

Was this helpful?

/