# How to get login\_count in useUser object in Next.js

**URL:** <https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [February 2, 2023, 3:42pm UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572 "2023-02-02T15:42:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuco312](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/fuco312/32/44276_2.png) [@fuco312](https://community.auth0.com/u/fuco312)\
**Post date:** [February 2, 2023, 3:42pm UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572/1 "2023-02-02T15:42:58Z")

</div>

Hello there ! I somehow cannot get access to user\_metadata, or login\_count inside my user object from useUser hook. I’ve been looking at multiple guides, and tutorials, and I don’t really understand what is going on. Can you guys please help me with some simple steps for accessing login\_count data in my Next.js application ? I’ve already seen topic which were setting up rules, or actions but none of them were working, and I didn’t get any other data in the user object.

---

<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 2, 2023, 5:48pm UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572/3 "2023-02-02T17:48:09Z")

</div>

Hi @fuco312,

Welcome to the Auth0 Community!

The `useUser` hook from the Next.js SDK only returns the following user profile attributes:

- `email_verified?`
- `name?`
- `nickname?`
- `org_id?`
- `picture?`
- `sub?`
- `updated_at?`

(Reference: [UserProfile | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/interfaces/client_use_user.UserProfile.html))

For getting the logins\_count for each user, I recommend using the [Management API Get a User endpoint](https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id) with the `fields` parameter to filter for the `logins_count` attribute.

Here is an example request:

```auto
curl --location -g --request GET 'https://{{auth0_domain}}/api/v2/users/:id?fields=logins_count' \
--header 'Authorization: Bearer {{auth0_token}}'

```

Alternatively, you could append the user’s `logins_count` as a custom claim to your token using an Auth0 Post Login Action. Then after login, you can decode the token and find the logins\_count claim. See our [Adding custom claims to tokens](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590) FAQ to learn more.

I hope this helps!

Please let me know if there’s anything else I can do to help.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![fuco312](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/fuco312/32/44276_2.png) [@fuco312](https://community.auth0.com/u/fuco312)\
**Post date:** [February 3, 2023, 9:04am UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572/4 "2023-02-03T09:04:15Z")

</div>

> [@rueben.tiow](#):
>
> `Authorization: Bearer {{auth0_token}}`

Hello @rueben.tiow thank you for replying, I’m trying to create the get request, but I’m not exactly sure where can I get the token from. My request is currently looking like this. The token is a value I’ve got from postman, but I’m not sure if it’s the right token. My results are bad request 400 - Bad HTTP authentication header format

 ![Screenshot 2023-02-03 at 10.02.42](https://global.discourse-cdn.com/auth0/original/3X/7/3/730ed58fb8088aa40036045ea7e83f28e846c5a6.png)

---

<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 3, 2023, 8:15pm UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572/5 "2023-02-03T20:15:12Z")

</div>

Hi @fuco312

Thank you for your response.

There are a couple of ways to get an Access Token for the Management API, namely, in the Auth0 Dashboard or calling the Management API using the client credentials flow.

Firstly, I recommend going to your [Auth0 Dashboard \> Applications \> APIs](https://manage.auth0.com/#/apis) and selecting your **Auth0 Management API**.

In the settings page, click on the **API Explorer** tab and if setup already, you should be able to copy the token directly from that page:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/8/a/8a73807021fa5a6708e5905e7be5eb605c5a24ed.jpeg)

Alternatively, you can programmatically get an access token by using the Client Credentials flow. For this, please click on the **Test** tab of your Management API, select your programming language, and copy the corresponding code.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/b/a/ba7d0f3acbf0925387df63d1b81d736edaa711f3.jpeg)

Then once you have gotten your token, you can use it to query the Management API’s Get a User endpoint.

Reference:

- [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production)

I hope the explanation is clear!

Please let me know if you have any additional questions. I’d be happy to help.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![fuco312](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/fuco312/32/44276_2.png) [@fuco312](https://community.auth0.com/u/fuco312)\
**Post date:** [February 3, 2023, 8:34pm UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572/6 "2023-02-03T20:34:15Z")

</div>

Thank you very much @rueben.tiow , I think that this has explained everything perfectly even to newbie like me ! Once again thank you very much for your time 🙂 Have a nice weekend !

---

<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:** [February 17, 2023, 8:35pm UTC](https://community.auth0.com/t/how-to-get-login-count-in-useuser-object-in-next-js/99572/7 "2023-02-17T20:35:04Z")

</div>

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