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

**URL:** <https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978>\
**Category:** Get Help\
**Tags:** account-linking, user-management\
**Created:** [December 13, 2023, 10:41am UTC](https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978 "2023-12-13T10:41:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vladz/32/53243_2.png) [@vladz](https://community.auth0.com/u/vladz)\
**Post date:** [December 13, 2023, 10:41am UTC](https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978/1 "2023-12-13T10:41:38Z")

</div>

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!

-Vlad

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [December 13, 2023, 3:33pm UTC](https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978/2 "2023-12-13T15:33:53Z")

</div>

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.

> **[Manage User Metadata with the post-login Action Trigger](https://auth0.com/docs/manage-users/user-accounts/metadata/manage-user-metadata)**
>
> Learn how to use the post-login Action trigger to modify user\_metadata and app\_metadata as part of a user’s login flow.

> **[Understand How Auth0 Actions Work](https://auth0.com/docs/customize/actions/actions-overview#what-can-you-do-with-actions-https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)**
>
> Describes how Auth0 Actions work and what you can accomplish with them.

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![vladz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vladz/32/53243_2.png) [@vladz](https://community.auth0.com/u/vladz)\
**Post date:** [December 13, 2023, 5:14pm UTC](https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978/3 "2023-12-13T17:14:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [December 19, 2023, 6:19pm UTC](https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978/5 "2023-12-19T18:19:35Z")

</div>

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](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/api-object#:~:text=In%20scenarios%20that%20require%20linking%20users%2C%20the%20user%20identity%20used%20to%20initiate%20the%20login%20may%20no%20longer%20exist%20as%20a%20discrete%20user).  
Let me know if everything is working correctly. If not, we can troubleshoot.

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 2, 2024, 6:20pm UTC](https://community.auth0.com/t/link-accounts-in-post-login-action-will-next-handler-see-the-change/122978/6 "2024-01-02T18:20:08Z")

</div>

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