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). 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). 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:
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