# Auth0 Actions: Find the Login count for SSO users

**URL:** <https://community.auth0.com/t/auth0-actions-find-the-login-count-for-sso-users/119613>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [October 27, 2023, 9:48pm UTC](https://community.auth0.com/t/auth0-actions-find-the-login-count-for-sso-users/119613 "2023-10-27T21:48:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alyssa.wolejko](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@alyssa.wolejko](https://community.auth0.com/u/alyssa.wolejko)\
**Post date:** [October 27, 2023, 9:48pm UTC](https://community.auth0.com/t/auth0-actions-find-the-login-count-for-sso-users/119613/1 "2023-10-27T21:48:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [October 29, 2023, 7:37pm UTC](https://community.auth0.com/t/auth0-actions-find-the-login-count-for-sso-users/119613/3 "2023-10-29T19:37:40Z")

</div>

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](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) I put something together just to give you an idea, see below:

```auto
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

---

<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 12, 2023, 7:37pm UTC](https://community.auth0.com/t/auth0-actions-find-the-login-count-for-sso-users/119613/4 "2023-11-12T19:37:54Z")

</div>

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