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
- checks if (connectionTypeMatches && isMissingMetadata)
- queries an endpoint - let newData = await axios.post(‘getMissingDataEndpoint’, data, options)
- sets App_Metadata from newData
- 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”