Account Linking Did Not Occur Because loginsCount = 2 on First Apparent Login

Problem statement

When using the Account Linking Extension to link user accounts, there are occasionally times when a user should have been prompted to link accounts but did not. This article explains why, in these cases, it looks like the user’s first log with a “Successful Login” is showing loginsCount: 2.

Troubleshooting

Check the user’s created_at date and see if it is earlier than the first log showing a “Successful Login”.

Cause

If a user triggers the Account Linking Extension and then abandons the account linking process (ex., they give up on trying to enter the credentials for the second account and close the tab), no log is generated for the initial successful login. If that session expires, the next login attempt will show loginsCount:2, even though it appears to be the first log they have of a Successful Login.

Solution

Since Rules will hit EOL later in 2024, the recommended approach would be to disable the extension and migrate to handling account linking in an Action where, instead of using loginsCount, use an app_metadatastate value to determine if linking should occur.

Here is an example Action from our docs that also handles the redirect for a user to enter the credentials of the second account:

The other option would be to modify the Rule automatically generated from the Account Linking Extension to use an app_metadata state value similar to how the Action example does instead of context.stats.loginsCount. For example, update the user’s app_metadata on line 135 in the Rule, then change the firstLogin() function on line 68 to check if the app_metadata value exists. Here is a link to our docs showing how to manage metadata in Rules if you use this option:

https://auth0.com/docs/manage-users/user-accounts/metadata/manage-metadata-rules