# api.user.setAppMetadata does not work in post login action

**URL:** <https://community.auth0.com/t/api-user-setappmetadata-does-not-work-in-post-login-action/130569>\
**Category:** Get Help\
**Tags:** actions-management-api, management-api\
**Created:** [March 26, 2024, 10:11pm UTC](https://community.auth0.com/t/api-user-setappmetadata-does-not-work-in-post-login-action/130569 "2024-03-26T22:11:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThomasFisher](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@ThomasFisher](https://community.auth0.com/u/ThomasFisher)\
**Post date:** [March 26, 2024, 10:11pm UTC](https://community.auth0.com/t/api-user-setappmetadata-does-not-work-in-post-login-action/130569/1 "2024-03-26T22:11:53Z")

</div>

We have a scenario where certain users with a certain connection type may log in with missing App\_Metadata. To remedy this, we have a post-login action that

1. checks if (connectionTypeMatches && isMissingMetadata)
2. queries an endpoint - let newData = await axios.post(‘getMissingDataEndpoint’, data, options)
3. sets App\_Metadata from newData
4. updates profile claims on idToken and accessToken

The first problem I am running into is in step 3, calling api.user.setAppMetadata(({ id: event.user\_id }, { profile: newProfile }); does not update the user’s app\_metadata.

I found this post:

> [@Set User Metadata Is Not Working Inside Post Login Action](https://community.auth0.com/t/set-user-metadata-is-not-working-inside-post-login-action/72744):
>
> Hi, this is Yasin. Problem This is for social login providers. I am trying to set the user metadata and read it after setting it, in a single post login action file. However, I get an error. Either the user metadata cannot set on Step 5 or the newly set user metadata cannot be read in Step 6 because I get an error This is a fundamental issue and I have to solve it as quickly as possible. Thank you so much! Post Login Action - Code Flow (Please read) Code flow is like this: Check if t…

and decided to comment out the updates to the idToken and accessToken to prep for potentially moving that logic into a new action. However, when I run the action in debug mode with a custom event pointed to a test account, the action completes successfully, but the test account does not get the expected metadata updates. I have logged the new data, confirmed everything is being queried correctly, and that the new data is being built as expected. I even see in the Test Results pane a Commands array with a SetMetadata command in it, and the command seems to have the relevant correct data. When I refresh the user’s detail page after running it though, the updates are not present on the profile.

This link mentions it should be possible to add the management api as a dependency to the action and update it that way:  
[https://community.auth0.com/t/different-strategies-to-update-user-metadata-in-post-login-action/121908](https://community.auth0.com/t/different-strategies-to-update-user-metadata-in-post-login-action/121908)  
However, when I try that, I get a “management.updateAppMetadata is not a function”

---

<div class="post-metadata">

**Author:** ![ThomasFisher](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@ThomasFisher](https://community.auth0.com/u/ThomasFisher)\
**Post date:** [March 28, 2024, 2:25pm UTC](https://community.auth0.com/t/api-user-setappmetadata-does-not-work-in-post-login-action/130569/2 "2024-03-28T14:25:38Z")

</div>

The best I could tell was happening here is that the action did not like waiting for a response from the endpoint. Ended up just reworking the endpoint being hit to include the extra management-api logic.

- This is not ideal, as it makes it impossible to put the profile updates on the issued token. We had to solve this through more hacks w/ silent authentication.

---

<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:** [April 11, 2024, 2:26pm UTC](https://community.auth0.com/t/api-user-setappmetadata-does-not-work-in-post-login-action/130569/3 "2024-04-11T14:26:36Z")

</div>

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