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

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:

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:

However, when I try that, I get a “management.updateAppMetadata is not a function”

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.

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