How to get login_count in useUser object in Next.js

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)

For getting the logins_count for each user, I recommend using the Management API Get a User endpoint with the fields parameter to filter for the logins_count attribute.

Here is an example request:

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 FAQ to learn more.

I hope this helps!

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

Thanks,
Rueben

1 Like