Last_login and logins_count Attributes not Updated after Account Linking

Problem statement

When performing Account linking via the Management API, the last_login and logins_count are not updated with secondary account activity until the user logs in again.

Symptoms

After linking accounts, the last_login and logins_count attributes are older than the secondary account activity and not updated until the user logs in again.

Cause

When account linking, the primary user’s profile is retained, but the majority of a secondary account’s profile is discarded. Only key features such as the old user_id, email or phone verification status, and email or phone number values, for example, are retained within the “profileData” object inside the identities array. Please see User Account Linking for more details

Thus, after linking, the last_login and logins_count attributes will be the same as the primary account’s last login activity, and the activity of any secondary accounts prior to the linking will not be taken into account.

If metadata should be merged, steps need to be taken to transfer the metadata across using the Management API to patch it into the primary account. Please see User Account Linking - Metadata merge for more details.

Solution

It is recommended when account linking to get the user to authenticate into all accounts that are to be linked before initiating the link to prove the user has ownership of all accounts.

This also has the benefit of updating the last_login and logins_count attributes to when the designated primary account was authenticated most recently.

Here are examples of performing account linking that show methods of authenticating the additional accounts:

Otherwise, the last_login and logins_count attributes will be updated the next time the user logs in with any of the now-linked accounts.