Auth0 Actions: Find the Login count for SSO users

Is there a way to determine in Auth0 Actions what the login count is for SSO users?

I need to run a script to our external API on the first login, but according to what I found… the event.logins_count doesn’t increment for SSO users with an active session.

Hi @alyssa.wolejko

Welcome to the Auth0 Community.

You are correct in that the event.stats.logins_count field within Actions is not incremented if the user already has a session in Auth0 and does not need to provide credentials (e.g SSO, silent authentication). To count every login including those made via SSO or silent authentication I anticipate you may need to create a custom app_metadata field and update that via a Post Login Action I put something together just to give you an idea, see below:

exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.app_metadata.EveryLoginCount) {
    api.user.setAppMetadata("EveryLoginCount", 1);
  } else {
    let loginCount = event.user.app_metadata.EveryLoginCount + 1
    api.user.setAppMetadata("EveryLoginCount", loginCount);

It may be logical to assume that the difference between your custom field and event.stats.logins_count is the SSO/silent auth number but this may need further testing to confirm this.

I hope this helps.

Warm regards

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