# Auth0 post-login Action firing unexpectedly

**URL:** <https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [May 15, 2023, 3:12pm UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937 "2023-05-15T15:12:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylanswartz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dylanswartz/32/47223_2.png) [@dylanswartz](https://community.auth0.com/u/dylanswartz)\
**Post date:** [May 15, 2023, 3:12pm UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937/1 "2023-05-15T15:12:27Z")

</div>

Hey Folks!

I’m attempting to send a notification to slack every time a user signs up for an account for my application [(as per this guide)](https://auth0.com/blog/send-slack-message-after-sign-up-with-auth0-actions/). Unfortunately, The post-user-registration doesn’t work as we have social logins enabled and I have confirmed the action does not run when a user authenticates with Google.

This led me down the path of using post-login and writing logic to only execute on first login ([see this post](https://community.auth0.com/t/how-to-distinguish-first-login-after-sign-up/94885/4)). However I’m still seeing the action execute multiple times for users even though their login count is not incremented.

Here is the code for my action:

```auto
exports.onExecutePostLogin = async (event, api) => {

  // post-user-registration does not work for social logins so this solution was found here: 
  // https://community.auth0.com/t/how-to-distinguish-first-login-after-sign-up/94885
  // check if user has more than one login, or if this is a refresh token rotation, or a silent auth request
  const not_first_login = event.stats.logins_count > 1 ||
                          event.transaction?.protocol === 'oauth2-refresh-token' ||
                          event.request.query?.prompt === 'none';
  if (not_first_login) {
    console.log(`Skipping event for user ${event.user.user_id}`);
    return;
  }

  const initSlackNotify = require('slack-notify')

  const slack = initSlackNotify(event.secrets.SLACK_WEBHOOK_URL);
  const message = `New User: ${event.user.email}`

  slack.success({
    text: message
  })

};

```

I’ve received the slack notification at the following increments for one user that signed up on May 9th at 5:15am:  
May 9th at 5:15am  
May 10th at 10:20am  
May 12 at 9:36am  
May 15th at 6:07am

This user’s login count is still at 1 and the Auth0 dashboard shows that they logged in “6 days ago”. Any ideas?

Please pass this along as a formal feature request for post-user-registration to fire on social logins not just username/password database logins.

Dylan

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [May 15, 2023, 4:05pm UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937/2 "2023-05-15T16:05:05Z")

</div>

Hi @dylanswartz 👋

In addition to logins, the Post-Login Flow Auth0 Actions also execute when re-authenticating user sessions via [refresh token rotations](https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation) requests ( `oauth2-refresh-token` event transaction protocol) & [silent authentication](https://auth0.com/docs/authenticate/login/configure-silent-authentication) requests ( `prompt=none` in /authorize requests)

Depending on your implementation of Auth0, there may be other protocols that are triggering your Post-Login action that I didn’t take into account when writing the conditional. Sorry!  
Take a look at the available protocols in the event.transaction object here: [Actions Triggers: post-login - Event Object](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object)

There is also this [existing feedback post](https://community.auth0.com/t/trigger-the-pre-user-registration-flow-for-social-and-other-non-database-connection-types/81070) that may interest you, if you’d like to vote on it.

---

<div class="post-metadata">

**Author:** ![dylanswartz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dylanswartz/32/47223_2.png) [@dylanswartz](https://community.auth0.com/u/dylanswartz)\
**Post date:** [May 17, 2023, 3:39pm UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937/3 "2023-05-17T15:39:13Z")

</div>

Is there a way to identify via logs or something like that what other protocols are being used? We only use the email/password login and google social login on our React web app. Nothing too fancy.

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [May 17, 2023, 6:10pm UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937/4 "2023-05-17T18:10:15Z")

</div>

@dylanswartz  
You should be able to view your tenant logs and look at the event type that is triggering your Auth0 Actions - if you see the post-login Action under the “Action Details” tab for anything other than the “Successful login” event (type: “s”), that could help you discover the issue.  
The different kind of Log Event codes can be found here: [Log Event Type Codes](https://auth0.com/docs/deploy-monitor/logs/log-event-type-codes)  
Let me know what event type you are seeing, and I’ll try to help you further 🙏

Also, if you’re able to replicate the Auth0 post-login action firing unexpectedly yourself, you can add `console.log` commands in your Auth0 Action and install the [Real-time Webtask Log Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs) to debug the issue.  
But I suggest doing this on a development or staging tenant if possible.

---

<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:** [January 8, 2024, 11:59am UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937/5 "2024-01-08T11:59:26Z")

</div>

Hey there!

As this topic is related to Actions and Rules & Hooks are being deprecated soon in favor of Actions, I’m excited to let you know about our next [Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043) on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

[Learn more here!](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 26, 2024, 11:55pm UTC](https://community.auth0.com/t/auth0-post-login-action-firing-unexpectedly/106937/6 "2024-11-26T23:55:43Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
