Different Strategies to Update User Metadata in Post-Login Action

Problem statement

In Post-Login Actions it’s possible to save user metadata with the following methods:

api.user.setAppMetadata(name, value)
api.user.setUserMetadata(name, value)

However, it’s also possible to instantiate the ManagementClient in an Action to save user metadata. Are there any tradeoffs to choosing one method over the other?

Solution

In the case of updating user metadata, the primary difference is that the ‘API’ method surfaced by the Action will aggregate calls to update a user’s metadata and only make an update once all Actions have run. This means the updated user metadata will not appear updated while the Actions are running for that login transaction.

On the other hand, updating the user with the ManagementClient will update the user immediately, and the change will be available in the Action during that login transaction.