# Actions: How do I \*set\* an event.user.nickname?

**URL:** <https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266>\
**Category:** Get Help\
**Tags:** other-built-in-social-connections, connections\
**Created:** [October 11, 2023, 7:54am UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266 "2023-10-11T07:54:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![edent](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edent/32/45781_2.png) [@edent](https://community.auth0.com/u/edent)\
**Post date:** [October 11, 2023, 7:54am UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/1 "2023-10-11T07:54:28Z")

</div>

I have this action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Put the user screen_name as the nickname
  // for Twitter connections
  if (event.connection.name === 'twitter' && event.user.screen_name) {
    event.user.nickname = event.user.screen_name;
  } 
};

```

This doesn’t set the user’s nickname.

I can do this: `api.user.setUserMetadata("nickname", "event.user.screen_name");`  
But that only adds it to the metadata.

I need the user’s object to contain the data.

Is there any way to set the nickname using an action?

---

<div class="post-metadata">

**Author:** ![edent](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edent/32/45781_2.png) [@edent](https://community.auth0.com/u/edent)\
**Post date:** [October 11, 2023, 8:41am UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/2 "2023-10-11T08:41:20Z")

</div>

Incidentally, this is a workaround for a bug that’s now 5 years old…

> [@Twitter nickname is not the same as screen\_name](https://community.auth0.com/t/twitter-nickname-is-not-the-same-as-screen-name/17297):
>
> My Twitter handle is @edent. If I login with Auth0, I see: 'nickname' =\> 'Terence Eden', 'name' =\> 'Terence Eden', I would expect my “nickname” to be the same as my screen\_name. If I log in with GitHub (Where I am also @edent) I get: 'nickname' =\> 'edent', 'name' =\> 'Terence Eden', I’m using the PHP library, if that makes a difference? use Auth0\SDK\Auth0; $auth0 = new Auth0([ 'domain' =\> AUTH0\_DOMAIN, 'client\_id' =\> AUTH0\_CLIENT\_ID, 'client\_secret' =\> AUTH0\_CLIENT\_…

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [October 11, 2023, 5:39pm UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/3 "2023-10-11T17:39:21Z")

</div>

hey @edent 👋

I can’t speak much regarding the bug you mention from 5 years ago, but if you need to update something other than `user_metadata` or `app_metadata` on user profiles in Auth0 Actions, you will have to use the Management API.

See this FAQ for more info on how to set it up  
[https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947)

Also, as noted in the FAQ above, the Management API updates are rate limited, so be sure to also add a check that the user’s `event.user.nickname` doesn’t already match `event.user.screen_name` before making the Management API request.

Hope this helps 🤞

EDIT:  
Something I forgot to mention, if you need to update `nickname` on social users, please note the following from this doc [Configure Identity Provider Connection for User Profile Updates](https://auth0.com/docs/manage-users/user-accounts/user-profiles/configure-connection-sync-with-auth0)

> By default, user profile attributes provided by identity providers other than Auth0 (such as Google, Facebook, Twitter) are not directly editable because they are updated from the identity provider each time the user logs in.
> 
> To be able to edit the name, nickname, given\_name, family\_name, or picture root attributes on the normalized user profile, you must configure your connection sync with Auth0 so that user attributes will be updated from the identity provider only on user profile creation.

---

<div class="post-metadata">

**Author:** ![edent](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edent/32/45781_2.png) [@edent](https://community.auth0.com/u/edent)\
**Post date:** [October 11, 2023, 6:17pm UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/4 "2023-10-11T18:17:32Z")

</div>

Wait, I have to set up and configure _another_ application, to call an API, to fix a bug, all because Auth0 have decided to deprecate something that worked?

Can I just pay someone at Okta to fix this bug?

Seriously, gang, I’ve got £5 here for any employee of Auth0 who wants to make this right.

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [October 11, 2023, 6:58pm UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/5 "2023-10-11T18:58:36Z")

</div>

Hey @edent

I took a closer look at the older post you made, are you looking to just temporarily override the `nickname` field for the ID Token on the frontend or the Access Token for the `/userinfo` endpoint?

I haven’t tested this, but try setting the nickname via the built-in api `setCustomClaim` functions.

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Put the user screen_name as the nickname
  // for Twitter connections
  if (event.connection.name === 'twitter' && event.user.screen_name) {
    api.idToken.setCustomClaim('nickname', event.user.screen_name);
    api.accessToken.setCustomClaim('nickname', event.user.screen_name);
  } 
};

```

Generally you would create a custom claim in the tokens with a namespace you own, but give this a try and see if this will resolve your issue.

---

<div class="post-metadata">

**Author:** ![edent](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/edent/32/45781_2.png) [@edent](https://community.auth0.com/u/edent)\
**Post date:** [October 11, 2023, 8:16pm UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/6 "2023-10-11T20:16:10Z")

</div>

That seems to work! Thank you.

Nevertheless, I think it’s time for me to move away from Auth0 if I can. It’s quite clear that they’ve no interest in fixing bugs and would rather spend their time changing their logo.

---

<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:** [October 25, 2023, 8:16pm UTC](https://community.auth0.com/t/actions-how-do-i-set-an-event-user-nickname/118266/7 "2023-10-25T20:16:30Z")

</div>

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