# Fetching user's username and printing to web app

**URL:** <https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [November 28, 2022, 9:41pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251 "2022-11-28T21:41:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![horsaen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/horsaen/32/41551_2.png) [@horsaen](https://community.auth0.com/u/horsaen)\
**Post date:** [November 28, 2022, 9:41pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/1 "2022-11-28T21:41:38Z")

</div>

Hey, I’m unable to print a given user’s username onto the page, similar to something like printing the user’s email or nickname with {user.nickname}. Upon further the user’s username is not listed in the /api/auth/me response, and login via username is confirmed to be on and working. I have also read the API scope docs but that has not proved useful as the username is not considered to be part of the user metadata, as listed in the raw JSON output on auth0’s console. So, any ideas how to make the username appear + print it on a NextJS web app? Thanks 🙂

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 28, 2022, 11:07pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/3 "2022-11-28T23:07:09Z")

</div>

Hey there @horsaen welcome to the community!

> [@horsaen](#):
>
> Upon further the user’s username is not listed in the /api/auth/me response, and login via username is confirmed to be on and working.

The user’s `username` should be able to be accessed at `user.name` which I would expect to be included in the `/api/auth/me` response as well as by using `userUser()` hook as outlined in our Nextjs [quickstart](https://auth0.com/docs/quickstart/webapp/nextjs#show-user-profile-information). The sample app has an example of using the `useUser()` hook:

> <https://github.com/auth0-samples/auth0-nextjs-samples/blob/766ec90cee03d95409accf504469cc4f827cd56f/Sample-01/pages/profile.jsx#L28>

Hope this helps!

---

<div class="post-metadata">

**Author:** ![horsaen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/horsaen/32/41551_2.png) [@horsaen](https://community.auth0.com/u/horsaen)\
**Post date:** [November 28, 2022, 11:31pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/4 "2022-11-28T23:31:51Z")

</div>

Hey !! thank you and thanks for your response !! 🙂

Unfortunately I have already tried this, and while the name is accessible from the /me path, it is not quite what I had hoped for, here’s what is listed in the /me response:

```auto
{
"nickname":"atealltheglue",
"name":"atealltheglue@*.com",
"picture":"https://s.gravatar.com/avatar/42bc28341cd33b6740463a25780f5df3?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fat.png",
"updated_at":"2022-11-28T20:33:10.297Z",
"email":"atealltheglue@*.com",
"email_verified":false,
"sub":"xxx",
"sid":"xxx"
}

```

and this is what is show in the account’s raw JSON file

```auto
{
    "created_at": "2022-11-28T20:33:10.297Z",
    "email": "atealltheglue@*.com",
    "email_verified": false,
    "identities": [
        {
            "connection": "Username-Password-Authentication",
            "provider": "auth0",
            "user_id": "63851b06802804f3214d0da7",
            "isSocial": false
        }
    ],
    "name": "atealltheglue@*.com",
    "nickname": "atealltheglue",
    "picture": "https://s.gravatar.com/avatar/42bc28341cd33b6740463a25780f5df3?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fat.png",
    "updated_at": "2022-11-28T21:39:27.462Z",
    "user_id": "auth0|63851b06802804f3214d0da7",
    "username": "horsaen",
    "user_metadata": {
        "sus": true
    },
    "last_ip": "*",
    "last_login": "2022-11-28T20:33:10.291Z",
    "logins_count": 1,
    "blocked_for": [],
    "guardian_authenticators": []
}

```

my main goal is to somehow access the ‘horsaen’ value, which is not present in the /me response mentioned above, also please note i did try adding a value for the user metadata in an effort to make sure that the username would not be found there ^w^, ignore the actual values 😛

so any ideas ? :o

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 28, 2022, 11:52pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/5 "2022-11-28T23:52:35Z")

</div>

Ahh OK gotcha! That makes more sense now, thanks for further explanation 🙂

It _should_ be as simple as adding a custom `username` claim to the ID Token with a Post Login [Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow), like:

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

```

I’m testing in the sample app and after adding the username as a custom claim it is returned in the user profile by the `useUser()` hook.

Let us know! 🤞

---

<div class="post-metadata">

**Author:** ![horsaen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/horsaen/32/41551_2.png) [@horsaen](https://community.auth0.com/u/horsaen)\
**Post date:** [November 29, 2022, 12:17am UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/6 "2022-11-29T00:17:09Z")

</div>

oohh so the action certainly works and when running it a proper username is returned, however i still get nothing in the /me response :o, did i do something wrong ?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 29, 2022, 12:46am UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/7 "2022-11-29T00:46:42Z")

</div>

Hmm and you have added the action to Actions → Flows → Login in your Auth0 Dashboard?

> **[Write Your First Action](https://auth0.com/docs/customize/actions/write-your-first-action#attach-the-action-to-a-flow)**
>
> Learn how to write an Action, which includes choosing a flow, creating an Action and configuring it, and binding it to the flow.

Assuming that Action has been deployed and added to the login flow, you should be getting the `username` in the profile 🤔

---

<div class="post-metadata">

**Author:** ![horsaen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/horsaen/32/41551_2.png) [@horsaen](https://community.auth0.com/u/horsaen)\
**Post date:** [November 29, 2022, 12:58am UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/8 "2022-11-29T00:58:08Z")

</div>

![image](https://global.discourse-cdn.com/auth0/original/3X/6/e/6eb0627eacb4b81dddd064dd67ce915792dd95b0.png)  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/c/0cd55b953a21f990d69619d93be6afb687a11092.png)  
is this correct ? :o, still nothing sadly

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 29, 2022, 1:07am UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/9 "2022-11-29T01:07:37Z")

</div>

That looks correct to me!

Have you tried setting up the [sample app](https://github.com/auth0-samples/auth0-nextjs-samples) keyed to the same web app? I’m curious if the profile information is pulled in correctly there - While it uses the hook rather than `auth/me` the data should be the same.

---

<div class="post-metadata">

**Author:** ![horsaen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/horsaen/32/41551_2.png) [@horsaen](https://community.auth0.com/u/horsaen)\
**Post date:** [November 29, 2022, 1:23am UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/10 "2022-11-29T01:23:08Z")

</div>

emmm i have no idea what we did but after firing up the sample app and then running the original web app everything works as intended, weird :o. thanks a ton, i really appreciate all the help :))

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 29, 2022, 5:55pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/12 "2022-11-29T17:55:14Z")

</div>

No problem, happy to help 🙂 Good to know it’s functioning as expected for you now!

---

<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:** [December 13, 2022, 5:55pm UTC](https://community.auth0.com/t/fetching-users-username-and-printing-to-web-app/95251/13 "2022-12-13T17:55:26Z")

</div>

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