# How can I update(user profile) family\_name and given\_name for Regular Web Applications

**URL:** <https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [February 26, 2025, 8:44pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911 "2025-02-26T20:44:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![criz.c](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/criz.c/32/73235_2.png) [@criz.c](https://community.auth0.com/u/criz.c)\
**Post date:** [February 26, 2025, 8:44pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/1 "2025-02-26T20:44:30Z")

</div>

In Post-login trigger I created an action that collects family\_name and given\_name from a form.

```
 exports.onExecutePostLogin = async (event, api) => {
 const form_id = 'form_id';
 if(event.user.given_name==null || event.user.family_name==null)
 {
    api.prompt.render(form_id);
  }else{
     return;
  }
};

exports.onContinuePostLogin = async (event, api) => {  
 const givenName = event.prompt.fields.given_name;
 const familyName = event.prompt.fields.family_name;

 const ManagementClient = require('auth0').ManagementClient;

 const management = new ManagementClient({
     domain: event.secrets.domain,
     clientId: event.secrets.clientId,
     clientSecret: event.secrets.clientSecret
 });

 const params = { id: event.user.user_id};

 const data = {
   "family_name" : familyName,
   "given_name" : givenName
 }
 try{
   const res = await management.users.update(params, data);
   console.log("response ", res);
   
 }catch(e){
   console.log('logged error is', e);
 }
 return;
};

```

I have added the Dependencies auth0@4.18.0 to the action and secrets as well.

When I try to update/create user profile with family\_name and given\_name I’m getting the error below.

logged error is AuthApiError: Grant type ‘client\_credentials’ not allowed for the client.  
at OAuth.parseError (/data/layers/core.windows.net/K5K9mAdro\_Ps3rfuIeWZNilCuA4S63U8XEGvr8a7YI0=/node\_modules/auth0/dist/cjs/auth/base-auth-api.js:43:16)  
.  
.  
.  
at async UsersManager.update (/data/layers/core.windows.net/K5K9mAdro\_Ps3rfuIeWZNilCuA4S63U8XEGvr8a7YI0=/node\_modules/auth0/dist/cjs/management/\_\_generated/managers/users-manager.js:561:26)  
at async exports.onContinuePostLogin (/data/io/node22/ec817423-b816-47eb-9855-058bd48631e9/webtask.js:40:20) {  
error: ‘unauthorized\_client’,  
error\_description: “Grant type ‘client\_credentials’ not allowed for the client.”,  
statusCode: 403,  
body: `{"error":"unauthorized_client","error_description":"Grant type 'client_credentials' not allowed for the client.","error_uri":"https://manage.teranet.auth0app.com/docs/clients/client-grant-types"}`,  
.  
.

I tried to enable Client Credentials in Applications → Your Application → Advanced Settings → Grant Types, but this type is in disabled status since **it is not M2M**.

Please let me know how to update (or create if family/given name does not exist) user profile.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 26, 2025, 11:15pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/3 "2025-02-26T23:15:20Z")

</div>

Hi @criz.c

Welcome to the Auth0 Community!

In order to update or add data for the user, there is no need to create a `ManagementClient`. You can add these values inside user metadata in the `ContinuePostLoginAction` to be easily accessible:

```auto
  api.user.setUserMetadata('company_name', event.prompt.fields.company_name);

```

You can read more about this in our [documentation](https://auth0.com/docs/customize/forms/render#fields-and-shared-variables-data-in-actions).

You can also update that information directly during the login process:

```auto
event.user.family_name = event.prompt.fields.family_name;
event.user.given_name = event.prompt.fields.given_name;

```

Alternatively, you can do this inside the form directly, by creating a flow which contains similar code:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/4/9/49b91885b64764d22c4b8afc3745d75a3149ca12.png)

This would be the form:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/2/1/218fb9e196eeb967d1d377bb992aa597bd82b5ba.png)

This is the output inside the user raw JSON after a login:

```auto
"given_name": "Daniel",
 "family_name": "Smith",

```

Hope this helps! If you have any other questions, feel free to leave a reply!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![criz.c](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/criz.c/32/73235_2.png) [@criz.c](https://community.auth0.com/u/criz.c)\
**Post date:** [February 27, 2025, 2:10pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/4 "2025-02-27T14:10:56Z")

</div>

Hi Nik,

Thanks for your reply. I want the names inside the root user profile, not in user\_metadata, like below.

Raw JSON.  
{  
“email”: “[username@gmail.com](mailto:username@gmail.com)”,  
“email\_verified”: true,  
**“given\_name”: “firstName”,**  
**“family\_name”: “secondName”,**  
“name”: “firstName secondName”,  
“user\_metadata”: {},  
“created\_at”: “2025-02-09T23:37:07.665Z”,  
“updated\_at”: “2025-02-25T22:09:33.638Z”  
}

I tried your suggestion inside onContinuePostLogin as below

```
exports.onContinuePostLogin = async (event, api) => {  
event.user.family_name = event.prompt.fields.family_name;
event.user.given_name = event.prompt.fields.given_name;

```

};

It gives me the error warning ‘Use api.\* to apply changes’.

Please keep in mind initially given\_name and family\_name is not inside the User Profile(Raw JSON).

I really appreciate your time!  
Thanks,

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 27, 2025, 3:38pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/5 "2025-02-27T15:38:03Z")

</div>

Hi @criz.c

Thanks for the additional info.

If you want to have them in the root user profile, you can follow the suggestion above where you can update the user data directly in the form using an Update User Flow. That way, those attributes will be in the root profile and also visible in the RAW JSON in the dashboard.

> Alternatively, you can do this inside the form directly, by creating a flow which contains similar code:
> 
> ![image](https://global.discourse-cdn.com/auth0/original/3X/4/9/49b91885b64764d22c4b8afc3745d75a3149ca12.png)
> 
> This would be the form:
> 
> ![image](https://global.discourse-cdn.com/auth0/original/3X/2/1/218fb9e196eeb967d1d377bb992aa597bd82b5ba.png)
> 
> This is the output inside the user raw JSON after a login:
> 
> ```auto
> "given_name": "Daniel",
> "family_name": "Smith",
> 
> ```

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![criz.c](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/criz.c/32/73235_2.png) [@criz.c](https://community.auth0.com/u/criz.c)\
**Post date:** [February 27, 2025, 5:48pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/6 "2025-02-27T17:48:59Z")

</div>

I have added the flow after my form as below.

 ![Form](https://global.discourse-cdn.com/auth0/original/3X/e/a/ea410b74a7d963cd9c4ae88d7ca033788ec8d3fb.png)

And then added code inside flow as you have mentioned

 ![flow](https://global.discourse-cdn.com/auth0/original/3X/3/6/36e55f71d2c3673c0fe5a2f6ce2735d990a5483a.png)

My Action is

```
 exports.onExecutePostLogin = async (event, api) => {
 const form_id = 'ap_intDpyXxEiFZMFos8WMi32';
 if(event.user.given_name==null || event.user.family_name==null)
   {
      api.prompt.render(form_id);
   }
};

exports.onContinuePostLogin = async (event, api) => {}

```

If I don’t write onContinuePostLogin method inside Post-login trigger action, I get the following error.

“description”: “Invalid function signature for the "onContinuePostLogin" handler. Use "exports.onContinuePostLogin = async function(event, api) { }" as the signature.”,

I have included the form in json format in case if it helps to investigate.

```
   		{
	  "version": "4.0.0",
	  "form": {
		"name": "Blank form",
		"languages": {
		  "primary": "en"
		},
		"nodes": [
		  {
			"id": "step_xTZy",
			"type": "STEP",
			"coordinates": {
			  "x": 500,
			  "y": 0
			},
			"alias": "Update User",
			"config": {
			  "components": [
				{
				  "id": "given_name",
				  "category": "FIELD",
				  "type": "TEXT",
				  "label": "Given Name",
				  "required": true,
				  "sensitive": false,
				  "config": {
					"multiline": false,
					"placeholder": "Enter your first name",
					"min_length": 1,
					"max_length": 75
				  }
				},
				{
				  "id": "family_name",
				  "category": "FIELD",
				  "type": "TEXT",
				  "label": "Surname Name",
				  "required": true,
				  "sensitive": false,
				  "config": {
					"multiline": false,
					"placeholder": "Enter your second name",
					"min_length": 1,
					"max_length": 75
				  }
				},
				{
				  "id": "next_button_ZWmh",
				  "category": "BLOCK",
				  "type": "NEXT_BUTTON",
				  "config": {
					"text": "Continue"
				  }
				}
			  ],
			  "next_node": "flow_LXZk"
			}
		  },
		  {
			"id": "flow_LXZk",
			"type": "FLOW",
			"coordinates": {
			  "x": 1025,
			  "y": 217
			},
			"alias": "Update flow",
			"config": {
			  "flow_id": "#FLOW-1#",
			  "next_node": "$ending"
			}
		  }
		],
		"start": {
		  "next_node": "step_xTZy",
		  "coordinates": {
			"x": 0,
			"y": 0
		  }
		},
		"ending": {
		  "resume_flow": true,
		  "coordinates": {
			"x": 1361,
			"y": 32
		  }
		}
	  },
	  "flows": {
		"#FLOW-1#": {
		  "name": "Update user_profile",
		  "actions": [
			{
			  "id": "update_user_TXoV",
			  "type": "AUTH0",
			  "action": "UPDATE_USER",
			  "allow_failure": true,
			  "mask_output": true,
			  "params": {
				"connection_id": "#CONN-1#",
				"user_id": "{{context.user.user_id}}",
				"changes": {
				  "given_name": "{{fields.given_name}}",
				  "family_name": "{{fields.gamily_name}}"
				}
			  }
			}
		  ]
		}
	  },
	  "connections": {
		"#CONN-1#": {
		  "id": "ac_e7DPpp9JPpHUFF64eb3ebU",
		  "app_id": "AUTH0",
		  "name": "Auth0"
		}
	  }
	}

```

Also when I tried to add vault connection I get the error message as below

 ![valut_error](https://global.discourse-cdn.com/auth0/original/3X/6/3/6338c4f080753c406bc9d65b2677bcd64e01f8fb.png)

So it did not update user profile with family name and given name.

Do I have to add any code inside onContinuePostLogin to update with new values and fields.

Also I have three applications where users log-in and Need to do the same for all the users regardless of application to which they log-in.

Thank you,

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 27, 2025, 6:10pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/7 "2025-02-27T18:10:26Z")

</div>

Hi again

In order for you to use a flow, it needs a valid vault connection. It appears that the credentials that you are using are invalid when creating the vault. Please use the credentials of the API Explorer application.

Also, I can see that you perhaps misspelled the variable for the family name field:

```auto
"family_name": "{{fields.gamily_name}}" -> "family_name": "{{fields.family_name}}"

```

Also, make sure that the id of the specified fields are the ones you use in the `Update User` flow, otherwise the execution will throw in an error. Also, make sure to change the id of the `text components` inside the step.

When rendering the form, you can copy paste the rendering provided by the Forms feature and just add the condition for trigger. Since a form is possibly rendered, the exports.onContinuePostLogin is required.

I have imported your form on my end, changed the misspelled variable in the flow and it executed and updated the user with the info which is visible in the user raw JSON.

Hope this helps!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![criz.c](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/criz.c/32/73235_2.png) [@criz.c](https://community.auth0.com/u/criz.c)\
**Post date:** [February 27, 2025, 7:41pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/8 "2025-02-27T19:41:31Z")

</div>

_Thanks for notifying me the misspell. Also I could do the vault connection successfully and the user info was updated in user profile._

Is it possible from Post-User-Registration do the same?

My Post User Registration Action is

```
exports.onExecutePostUserRegistration = async (event, api) => {
   const FORM_ID = 'ap_intDpyXxEiFZMFos8WMi32';
   if(!event.user.given_name || !event.user.family_name){
      api.prompt.render(FORM_ID);    
    }
};

```

but it show the error below

Property ‘prompt’ does not exist on type ‘PostUserRegistrationAPI’.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 27, 2025, 8:12pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/9 "2025-02-27T20:12:14Z")

</div>

The forms cannot be rendered in `PostUserRegistration` triggers, they can only be rendered in `PostLogin` triggers.

If you wish for the form to be rendered upon registration, I would advise to check the login count of the user instead of checking if they have an assigned given and family name.

You could do something like:

```auto
if(event.user.logins_count === 1){
      api.prompt.render(FORM_ID);    
}

```

A newly registered user will always have a login count of 1 since the moment they sign up, that is considered their first successful login. However, that might not be suitable for existing members. If you have existing members, your approach would be more suitable. Also, the `PostLogin` trigger will work even on signup.

If you need any other clarifications, let me know!

Kind Regards,  
Nik

---

<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 13, 2025, 8:12pm UTC](https://community.auth0.com/t/how-can-i-update-user-profile-family-name-and-given-name-for-regular-web-applications/182911/10 "2025-03-13T20:12:37Z")

</div>

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