Problem statement
The Action code assigns a value to event.user.user_metadata[“hoo”].
console.log(event.user.user_metadata["hoo"]) // Outputs "Original Value"
event.user.user_metadata["hoo"] = "Updated Value"
However, the following Actions do not get this updated value.
// In the next Action...
console.log(event.user.user_metadata["hoo"]) // Still outputs "Original Value"
The same goes for event.user.app_metadata[“hoo”].
Steps to reproduce
- Create 2 Post Login Actions. Say Action 1 and 2. And add them to the flow.
- In Action 1, assign a value to event.user.user_metadata[“hoo”] or app_metadata[“hoo”]
- In the following Action 2, check the value of event.user.user_metadata[“hoo”] or app_metadata[“hoo”] (using Realtime Webtask Log)
Cause
The event.user object in Action is a read-only snapshot of the user data created when an Action is executed.
Assigning a value to event.user.user_metadata[“hoo”] or app_metadata[“hoo”] will not update the source user data in the database.
Solution
Use api.users.setUsermetadata method.
(setAppMetadata for app_metadata)
//Action 1
api.users.setUserMetadata("hoo", "Updated Value")
//Action 2
console.log(event.user.user_metadata["hoo"]) // Outputs "Updated Value"