Auth0 Action triggering more than once?

I have an action in the Login Flow that sends a New User message every time someone signs up. My code filters out only users who have a login_count of 1.


exports.onExecutePostLogin = async (event, api) => {
  // If user is logged in for the first time. 
  if (event.stats.logins_count === 1) {
    const slack = require('slack-notify')(event.secrets.SLACK_WEBHOOK_URL);
    
    const message = `New User: ${event.user.email} (${event.user.name || (event.user.given_name && event.user.family_name) || event.user.username || ""})`;
    const channel = '#new-users';

    slack.success({
    text: message,
    channel: channel
    });
}

However, my slack got a few identical messages. One at
12:05AM PST,
12:15 AM PST,
10:46PM PST on 10/05/2021.

Is the action triggering more than once?

Hi @robinhuang

Thank you for contacting Auth0 Community!!!

You can implement Post registration action for this purpose.

The current implementation you have is for post-login which will trigger every time the user logs in.

Hope it helps !!!

Thank you
Jeff

1 Like

Hi Jeff,

Thanks for the quick reply. My issue is, I want to notify signups through social logins too (fb, google). Post registration doesnā€™t trigger for these.

I feel like my implementation in the Login flow should work, given I filter by login_count.

Do actions trigger more than once with the same event? Any other way to get notified for social sign ups?

1 Like

Hi @robinhuang

I tested this myself and I figured post-login action also runs on Successful silent authentication. So if you login and your app also trigger a Silent Authentication check then that will be cause the post login to run again hence that action is triggered twice. You can check Actions triggered as part of login flows in Monitoring ā†’ Logs and select the Success Login event to see details.

Let me know if that is the reason in your case.

Thanks
Jeff

1 Like

Hi Jeff,

That makes sense. The logs show multiple ā€œSuccess Loginā€, even thought the login_count is 1. Is there way to discern that from the Login event in the Action?

Best,

Robin

Hi robin

You should be able to do this to detect silent auth.

if (event.request.query.prompt === ā€˜noneā€™) {
}

Thanks
Jeff

1 Like

Thank you so much for your help!

1 Like

We are here for you!

1 Like

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