Account Linking in Actions - How to Keep the User Logged In Loading

Problem statement

When using an Action to link new passwordless accounts to an existing database account with the same email, the user fails to log in and requires a re-login.

Symptoms

  • Performing Account Linking within an Action
  • Login failures for secondary accounts.

Troubleshooting

Check the Action code for how it performs the linking, particularly which account is considered the primary account.

Cause

When linking accounts, the secondary account will cease to exist as its own identity and will instead share the primary account’s User ID.

This can cause issues if the secondary account is what started the login transaction, as, by the end of the Action flow, the secondary User ID no longer exists.

Solution

Make sure when linking within an Action, if what is designated as the primary account is different from the user that began the login flow, to update the login context to the primary user before ending the Action flow, using:

api.authentication.setPrimaryUser(<primary_user_id_here>);

Related References