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

# Pre-user Registration Trigger

> Learn about the Pre User Registration Flow, which runs when a user attempts to register through a Database or Passwordless connection. It can be used to add metadata to the user profile before it is created or to deny a registration.

The Pre-user Registration trigger runs before a user is added to a Database or <Tooltip href="/docs/fr-CA/fr-ca/glossary?term=passwordless" tip="Sans mot de passe
Forme d’authentification qui ne repose pas sur un mot de passe comme premier facteur." cta="Voir le glossaire">Passwordless</Tooltip> Connection.

<Frame>
  <img src="https://mintcdn.com/generaltranslationinc/I3Fs4t2ino3YdzfZ/docs/images/fr-ca/cdy7uua7fh8z/2KtUcZhaBcT12GxjhBJZFG/9633b4454ac1c06c0deed6c97e70fe7d/pre-user-registration-flow.png?fit=max&auto=format&n=I3Fs4t2ino3YdzfZ&q=85&s=6e942b1d3b8694438ba8cb765a13d9a4" alt="Diagram showing the Actions Pre User Registration Flow." width="849" height="286" data-path="docs/images/fr-ca/cdy7uua7fh8z/2KtUcZhaBcT12GxjhBJZFG/9633b4454ac1c06c0deed6c97e70fe7d/pre-user-registration-flow.png" />
</Frame>

Actions in this flow are blocking (synchronous), which means they execute as part of a trigger's process and will prevent the rest of the Auth0 pipeline from running until the Action is complete.

<div id="triggers">
  ## Triggers
</div>

<div id="pre-user-registration">
  ### Pre-user Registration
</div>

The `pre-user-registration`  triggers runs when a user attempts to register through a Database or Passwordless connection. This trigger can be used to add metadata to the user profile before it is created or to deny a registration with custom logic.

<Warning>
  Vous ne pouvez pas présentement utiliser les Actons `pre-user-registration` pour ajouter des métadonnées aux utilisateurs sans mot de passe.
</Warning>

<div id="references">
  #### References
</div>

* [Event object](/docs/fr-CA/fr-ca/customize/actions/explore-triggers/signup-and-login-triggers/pre-user-registration-trigger/pre-user-registration-event-object): Provides contextual information about the request to register a new user.
* [API object](/docs/fr-CA/fr-ca/customize/actions/explore-triggers/signup-and-login-triggers/pre-user-registration-trigger/pre-user-registration-api-object): Provides methods for changing the behavior of the flow.

<div id="common-use-cases">
  ## Common use cases
</div>

<div id="deny-registration-by-location">
  ### Deny registration by location
</div>

A pre-user registration Action can be used to prevent a user from signing up.

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

<div id="set-metadata-in-the-user-profile">
  ### Set metadata in the user profile
</div>

A pre-user registration Action can be used to add metadata to the user profile before it is created.

<Warning>
  Vous ne pouvez pas présentement utiliser les Actons `pre-user-registration` pour ajouter des métadonnées aux utilisateurs sans mot de passe.
</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");  
};
```

<div id="store-a-user-id-from-another-system-in-the-user-profile">
  ### Store a user ID from another system in the user profile
</div>

A pre-user registration Action can be used to store a user ID from another system in the user profile.

```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">
  Pour utiliser une bibliothèque `npm` comme `axios`, vous devez ajouter la bibliothèque à l’Action en tant que dépendance. Pour en savoir plus, lisez la section « Ajouter une dépendance » dans [Rédigez votre première action](/docs/fr-CA/fr-ca/customize/actions/write-your-first-action).
</Callout>

<div id="deny-access-to-specific-ja3ja4-fingerprints">
  ### Deny access to specific JA3/JA4 fingerprints
</div>

The `event.security_context` object contains the JA3/JA4 fingerprint values for the current transaction.

```javascript lines theme={null}
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');
  }
};
```
