# Nickname contains the beginning of the email address instead of the provided username

**URL:** <https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351>\
**Category:** Get Help\
**Tags:** username, angular, login\
**Created:** [August 22, 2021, 2:22pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351 "2021-08-22T14:22:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jodi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jodi/32/12921_2.png) [@jodi](https://community.auth0.com/u/jodi)\
**Post date:** [August 22, 2021, 2:22pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/1 "2021-08-22T14:22:36Z")

</div>

Hi all,

I have turned on the “requires username” switch in the database - Username-Password-Authentication settings. Auth0 indeed asks the user for a username when signing up now.

However, when fetching the user using the Angular SDK, the nickname on the user object does not contain this username, instead it contains the first part of the email address. For example:

```auto
{
    email: "fakemail@test.com"
    email_verified: false
    name: "fakemail@test.com"
    nickname: "fakemail"
    picture: "...."
    sub: "...."
    updated_at: "...."
}

```

Instead of the “fakemail”, I would have expected the provided username.

How can I add this to the nickname field / add the username to the user object?  
I have been playing around with the Auth0 Rules but did not manage to create the expected behaviour.

Help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 23, 2021, 8:37pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/3 "2021-08-23T20:37:32Z")

</div>

Hi @jodi,

Welcome to the Auth0 Community!

You should see a `username` property, like this:

```auto
"username": "ExampleUser1"

```

The `nickname` claim is a bit different. It is [defined as follows](https://openid.net/specs/openid-connect-core-1_0.html):

> Casual name of the End-User that may or may not be the same as the given\_name. For instance, a nickname value of Mike might be returned alongside a given\_name value of Michael.

In this case, it is a truncated version of the `name` attribute.

---

<div class="post-metadata">

**Author:** ![jodi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jodi/32/12921_2.png) [@jodi](https://community.auth0.com/u/jodi)\
**Post date:** [August 23, 2021, 8:53pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/4 "2021-08-23T20:53:45Z")

</div>

Hi @dan.woda

Thanks for the response! Unfortunately I do not see a username property in the response I get from the $user call in angular.

Any idea how to get it there?

Thanks!  
Jodi

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 23, 2021, 9:05pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/5 "2021-08-23T21:05:20Z")

</div>

Do you see it in the user’s JSON object in the Auth0 dashboard?

---

<div class="post-metadata">

**Author:** ![jodi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jodi/32/12921_2.png) [@jodi](https://community.auth0.com/u/jodi)\
**Post date:** [August 23, 2021, 9:30pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/6 "2021-08-23T21:30:02Z")

</div>

@dan.woda,

I do see it in the auth0 user dashboard. It is displayed correctly there 🙂

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 26, 2021, 9:13pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/7 "2021-08-26T21:13:58Z")

</div>

It turns out that username is not a standard OIDC claim, and you must add it to the token in an action or rule. This post covers it:

> [@How to Retrieve Username with Auth0-spa-js](https://community.auth0.com/t/how-to-retrieve-username-with-auth0-spa-js/38940/3):
>
> username isn’t a standard OIDC claim (section 5.1 [Final: OpenID Connect Core 1.0 incorporating errata set 1](https://openid.net/specs/openid-connect-core-1_0.html)) so I believe it should be added via Rule to the ID token as custom claim. function (user, context, callback) { context.idToken['https://mynamespace/username'] = user.username; callback(null, user, context); } Alternatively, set it as preferred\_username in a pre-user-registration hook, which is a standard claim, and request the preferred\_username scope when doing the authorizatio…

---

<div class="post-metadata">

**Author:** ![jodi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jodi/32/12921_2.png) [@jodi](https://community.auth0.com/u/jodi)\
**Post date:** [August 28, 2021, 10:00am UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/8 "2021-08-28T10:00:50Z")

</div>

@dan.woda

Thanks, works perfectly!!

**Quick note for other people looking for the same solution:**

```auto
function (user, context, callback) { 
  context.idToken['https://mynamespace/username'] = user.username; 
  callback(null, user, context);  
}

```

the “mynamespace” in the above code block is not allowed to be any [auth0.com](http://auth0.com), [webtask.io](http://webtask.io) or webtask.run domain.

---

<div class="post-metadata">

**Author:** ![nacho](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nacho/32/12799_2.png) [@nacho](https://community.auth0.com/u/nacho)\
**Post date:** [August 29, 2021, 5:33pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/9 "2021-08-29T17:33:23Z")

</div>

How do you set username using action?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 30, 2021, 7:40pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/10 "2021-08-30T19:40:49Z")

</div>

> [@jodi](#):
>
> the “mynamespace” in the above code block is not allowed to be any [auth0.com](http://auth0.com), [webtask.io](http://webtask.io) or webtask.run domain.

Thanks for sharing this tip!

---

<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:** [September 14, 2021, 7:41pm UTC](https://community.auth0.com/t/nickname-contains-the-beginning-of-the-email-address-instead-of-the-provided-username/68351/11 "2021-09-14T19:41:42Z")

</div>

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