When is event.user updated in the Actions lifecycle, and how?

Hi,

There looks to be two ways to modify event.user in the trigger of an Action flow for the subsequent Actions in the same trigger to access updated user information using event.user:

  1. Use the management API to call one of the APIs that performs an update (eg: POST /identities, PATCH /api/v2/users/{id} etc)
  2. For instances where only the user or app metadata needs to be updated, the api object provides the necessary setters for that.

We tried both the approaches and noticed that for both of them, the subsequent Actions had an updated event.user object.

  1. Is the user record on Auth0 updated between Actions of the same trigger?
  2. Does every Action fetch the user record from the Auth0 database prior to execution? What about in the instance of the api object used to modify the user or app metadata — are changes to event.user made in-memory?
  3. How does the behaviour change when Actions are across multiple triggers (eg pre-user registration and post-login)?

Thanks

Hi @murtaza,

Welcome to the Auth0 Community!

I understand that you have questions about when the event.user object gets updated during the Actions pipeline.

Firstly, behind the scenes, Actions batches requests and immediately exits the function. By that time, if you attempt to SET the user_metadata and then GET, or vice versa, you will encounter issues with retrieving the latest values.

In this case, you will want to rewrite your Actions in an asynchronous manner using the await operator.

The different Action flows execute base on different triggers during the authentication pipeline, such as the Post-Login, Pre-User Registration, Post-User Registration Actions.

Please see this to learn more about how Actions work and when they execute during the authentication pipeline.

Hoped this help!

Please let me know if there’s anything else I can do to help.

Thank you.

Hi Reuben,

How is event.user updated between two Actions? For example, If I use the management API to update a user in ActionA, I have an updated user record in event.user in ActionB. How does ActionB have an updated event.user? Is it read from the database?

Separately, if I use api.setUserMetadata or api.setAppMetadata in ActionA, the event.user object in ActionB has updated user information. What is the source of truth for this? Is the user record in the database updated and read from before ActionB?

Thanks
— Murtaza

1 Like

Hey there!

As this topic is related to Actions and Rules & Hooks are being deprecated soon in favor of Actions, I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!