# Actions and pre-user-registration trigger

**URL:** <https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474>\
**Category:** Get Help\
**Tags:** login\
**Created:** [July 22, 2022, 12:29pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474 "2022-07-22T12:29:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brett2/32/22642_2.png) [@brett2](https://community.auth0.com/u/brett2)\
**Post date:** [July 22, 2022, 12:29pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/1 "2022-07-22T12:29:24Z")

</div>

I am learning Actions and am interested in the `pre-user-registration` trigger functionality. My end goal is to take action prior to an account getting created in Auth0.

Does this trigger fire when someone tries to login with a oAuth provider for the first time and BEFORE that `user identity` is saved as a user?

I am not grokking the documentation on what actions and when the trigger occurs.

Thank you!

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 22, 2022, 2:24pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/2 "2022-07-22T14:24:25Z")

</div>

From this documentation, it looks like the action is triggered before the user profile is entered into a database or passwordless connection.

> **[Pre User Registration Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow)**
>
> 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.

This would not apply to social or enterprise connections.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 22, 2022, 3:25pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/4 "2022-07-22T15:25:27Z")

</div>

Hi @josiah_devizia,

Thank you for sharing the solution with the rest of the Community!

If you encounter any further questions, please feel free to reach out.

Thank you.

---

<div class="post-metadata">

**Author:** ![brett2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brett2/32/22642_2.png) [@brett2](https://community.auth0.com/u/brett2)\
**Post date:** [July 22, 2022, 5:46pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/5 "2022-07-22T17:46:38Z")

</div>

> [@josiah\_devizia](#):
>
> This would not apply to social or enterprise connections.

Is there an actions trigger which does fire prior to a oAuth `user identity` being added as an account/user?

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 22, 2022, 6:00pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/6 "2022-07-22T18:00:31Z")

</div>

Here is the full list of triggers and flows for actions. I don’t think there is one that meets your criteria. Maybe @rueben.tiow can weigh in, whether this is possible or if a feature request is needed.

> **[Explore Flows and Triggers](https://auth0.com/docs/customize/actions/flows-and-triggers)**
>
> Learn about triggers, which are events that automatically invokes an Action when a specific operation, such as a user logging in, occurs at runtime.

---

<div class="post-metadata">

**Author:** ![brett2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brett2/32/22642_2.png) [@brett2](https://community.auth0.com/u/brett2)\
**Post date:** [July 23, 2022, 12:10pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/7 "2022-07-23T12:10:05Z")

</div>

Yeah I don’t understand how adding a new `user identity` (creating) when someone is LOGING IN in is a feature and not a bug. I seem to be the minority on this though.

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 25, 2022, 11:14am UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/8 "2022-07-25T11:14:55Z")

</div>

Well in the case that you are using a third party Identity Provider, Auth0 is not creating the user identity on login. They are creating a user profile in Auth0. The identity lives with the third party (social or enterprise connections).

---

<div class="post-metadata">

**Author:** ![brett2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brett2/32/22642_2.png) [@brett2](https://community.auth0.com/u/brett2)\
**Post date:** [July 25, 2022, 12:04pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/9 "2022-07-25T12:04:24Z")

</div>

> [@josiah\_devizia](#):
>
> They are creating a user profile in Auth0.

Thank you for the clarification. Is there a trigger or other method I can use to before this happens?

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 25, 2022, 12:16pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/10 "2022-07-25T12:16:25Z")

</div>

You can probably have an action that checks if this is a new profile on their first login.  
I would imagine in a post-login action you could check if `event.stats.logins_count` is 1 (or 0, i’m not sure when it increments).

> **[Actions Triggers: post-login - Event Object](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object)**
>
> Learn about the post-login Action trigger's event object, which provides contextual information about a single user logging in via Auth0.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 25, 2022, 3:57pm UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/11 "2022-07-25T15:57:08Z")

</div>

Hi @brett2 and @josiah_devizia,

Thank you both for the responses.

> [@josiah\_devizia](#):
>
> You can probably have an action that checks if this is a new profile on their first login.  
> I would imagine in a post-login action you could check if `event.stats.logins_count` is 1 (or 0, i’m not sure when it increments).

Yes, this would be a great workaround! For clarity, the login count will be 1 because Enterprise or Social users gets added to Auth0 regardless of clicking the “signing up” and “logging in” buttons. Meaning, that the user will always log in both sign-up and log-in flows.

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count === 1) {
    //Your logic here
  }
};

```

I hope this helps!

Please let me know if you have any additional questions.

Thank you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 10:51am UTC](https://community.auth0.com/t/actions-and-pre-user-registration-trigger/87474/12 "2022-12-22T10:51:18Z")

</div>


