# Adding loginCounts to GET /userinfo response

**URL:** <https://community.auth0.com/t/adding-logincounts-to-get-userinfo-response/78645>\
**Category:** Get Help\
**Tags:** userinfo\
**Created:** [February 21, 2022, 12:03pm UTC](https://community.auth0.com/t/adding-logincounts-to-get-userinfo-response/78645 "2022-02-21T12:03:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roy2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roy2/32/12835_2.png) [@roy2](https://community.auth0.com/u/roy2)\
**Post date:** [February 21, 2022, 12:03pm UTC](https://community.auth0.com/t/adding-logincounts-to-get-userinfo-response/78645/1 "2022-02-21T12:03:27Z")

</div>

Hi,  
I created the next rule:

```auto
function addAttributes(user, context, callback) {
  context.idToken['https://example.com/login_counts'] = context.stats.loginsCount || 0;
  context.idToken.login_counts = context.stats.loginsCount || 0;

  callback(null, user, context);
}

```

GET userinfo response BEFORE using the above rule was:

```auto
{
  "sub": "auth|012345"
  "nickname": "test" ,
  "name": "test@example.com",
  "picture": "..."
  "updated_at": "2022-02-21T11:49:20.539Z",
  "email": "test@example.com",
  "email_verified": false
}

```

AFTER using the rule:

```auto
{
  "sub": "auth|012345"
  "nickname": "test" ,
  "name": "test@example.com",
  "picture": "..."
  "updated_at": "2022-02-21T11:49:20.539Z",
  "email": "test@example.com",
  "email_verified": false,
  "https://example.com/login_counts": 208
}

```

EXPECTED

```auto
{
  ...
  "https://example.com/login_counts": 208
  "login_counts": 208
}

```

Any ideas???

Thanks.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 23, 2022, 1:35am UTC](https://community.auth0.com/t/adding-logincounts-to-get-userinfo-response/78645/3 "2022-02-23T01:35:53Z")

</div>

Hi @roy2,

Welcome to the Auth0 Community!

I understand you are looking to add the users _loginCount_ to the ID token.

After looking carefully at your Rule and response, everything looks correct. Because the _loginCount_ is not a part of the standard claims, you will need to append them as custom claims as you have already done using the Rule.

In this case, the result is to be expected with the custom claim appended to a namespace:

```auto
"https://example.com/login_counts" : 208

```

Our [Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims) documentation explains this in further detail.

Thus, to reiterate, you are appending namespaced custom claims to your ID token correctly.

Hoped this helps!

Please let me know if you have any further questions.

Thank you.

---

<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:** [March 10, 2022, 1:36am UTC](https://community.auth0.com/t/adding-logincounts-to-get-userinfo-response/78645/4 "2022-03-10T01:36:08Z")

</div>

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