# Connecting Auth0 users to a database

**URL:** <https://community.auth0.com/t/connecting-auth0-users-to-a-database/133368>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [May 3, 2024, 9:10pm UTC](https://community.auth0.com/t/connecting-auth0-users-to-a-database/133368 "2024-05-03T21:10:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrismcclarin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chrismcclarin/32/56789_2.png) [@chrismcclarin](https://community.auth0.com/u/chrismcclarin)\
**Post date:** [May 3, 2024, 9:10pm UTC](https://community.auth0.com/t/connecting-auth0-users-to-a-database/133368/1 "2024-05-03T21:10:58Z")

</div>

I have made a website using Next.Js. I used the quickstart and now I have a login and a log out and a user profile page.

When I use the useUser() hook, I get a user object that is the user profile. It provides me with this information

" {  
email: “[email]@hotmail.com”,  
email\_verified: false,  
name: “[email]@hotmail.com”,  
nickname: “[email]”,  
picture: “somepng.png”,  
sid: “some sesssion id”,  
sub: “user id”,  
updated\_at: “time”  
}

I removed identifing marks, but this is what I get.

Now, after they log in, I want to have something like “Hello, [name]” on my main page, but their name is their email. Even when I went into Auth0 dashboard and added username, that isn’t added to the profile.

So, without me manually doing anything, how do I get quick and easy access to the username of the user? Do I have to perform a fetch for all the user data and put it in a useEffect? or is there a way for the profile to have the username?

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [March 11, 2025, 10:48pm UTC](https://community.auth0.com/t/connecting-auth0-users-to-a-database/133368/3 "2025-03-11T22:48:53Z")

</div>

Hi @chrismcclarin,

Welcome to the Auth0 Community and sorry for the late reply.

You can add the username to the user profile by adding a custom claim to the ID Token with a **Post Login Action** such as :

```auto
exports.onExecutePostLogin = async (event, api) => {
    if (event.authorization) {
      api.idToken.setCustomClaim('username', event.user.username);
   }
}

```

Then, as you have already mentioned you can use the [useUser](https://auth0.github.io/nextjs-auth0/functions/client.useUser.html) function from the @auth0/nextjs-auth0 - v4.0.3 and fetch the user profile, including the username as well.

I hope this helps your case, but others as well.  
Thanks,  
Remus

---

<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 25, 2025, 10:49pm UTC](https://community.auth0.com/t/connecting-auth0-users-to-a-database/133368/4 "2025-03-25T22:49:37Z")

</div>

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