Link accounts in post-login action. Will next handler see the change?

Hi. I am linking user accounts based on email address in the post-login handler, and I set the primary user account using api.authentication.setPrimaryUser(). However, I have more than one handler in the post-login flow. Will the next handlers receive updated event.user, or if not, how should they know the primary user has changed and the user initially referenced by event.user no longer exists?
Thank you in advance!


Hi @vladz

Welcome to the Auth0 Community!

Thank you for posting your question!

According to our documentation about Actions Flows, post-login trigger is executed synchronous, so it will be run in placed order.

The processes that can be extended in this way are called flows. Each flow is made up of one or more triggers and represents the logical pipeline through which information moves during a single point in the Auth0 journey. Multiple Actions can be added to a trigger, with each Action executing in the order in which it was placed. Some triggers are executed synchronously, blocking the flow in which they are involved, and some are executed asynchronously, as indicated in the table below.

But remember that Multiple setUserMetadata or setAppMetadata calls will be batched together into a single user profile update at the end of the trigger’s execution, even if they are made by different Actions.


Hi Dawid.
Thank you for your answer! I know about setAppMetadata() batching, and my question was not exactly about that. I want to clarify whether the event.user gets updated when I link accounts and set another account to be the “authenticated user” using api.authentication.setPrimaryUser(). See the problem here? One handler merges the account currently logged in into another account and sets the “old” account as the “current user”. As a result of account linking, the account that just logged in (and referenced by event.user) no longer exists. Will the next post-login handler in the flow know about that?
Thanks again.

Hi @vladz

Thank you for your patience. As an answer to your question

Will the next post-login handler in the flow know about that?

Yes, It should retain user-A (setPrimaryuser) within the same login transaction flow until all actions have finished execution.

In scenarios that require linking users, the user identity used to initiate the login may no longer exist as a discrete user. That identity may now be a secondary identity of an existing user. In such situations, the setPrimaryUser() function can be used to indicate that the subject of the login should be changed.

Reference: Actions Triggers: post-login - API Object.
Let me know if everything is working correctly. If not, we can troubleshoot.


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