Attempting to Link a User to an Already Linked Identity - Results Does not Fail

Problem statement

When trying to link an Identity to a User, the User originally linked with the Identity is deleted and added to the new User.
Should there be an error or notification if the requested Identity is already linked to a User?

Steps to reproduce

  1. Link User 0 to User 1 - U1 now has two Identities linked
  • A Primary Identity with a unique User ID - (ID1) - which is the same as pre-linked U1
  • A Secondary Identity with a unique User ID - (ID2) - from its original User U0. After U0 was linked to U1, it was removed from the database.
  1. Create a new User - U2 - with one identity
  • created with a unique User ID - (ID3).
  1. Link ID2 to U2.
  • U2 - now has three accounts linked
    • A Primary Identity on the “guest-users” connection with User ID: ID3
    • A Secondary Identity on the “guest-users” connection with User ID: ID1
    • A Tertiary Identity on the “sms” connection with User ID: ID2
  • U1 has been removed from the database as U0 was originally. and no error was thrown, or notification was given.

Troubleshooting

If, after linking an Identity, a different User is removed from the database, check to see if the new User includes the Identity of the missing User.

Cause

The original Users looked like this:

  • U1 - has two Identities linked
    • A Primary Identity is created on the “guest-users” connection with a unique User ID - (ID1) - which is the same as pre-linked U1.
    • A Secondary Identity on the “sms” connection with a unique User ID - (ID2) - from its original User U0. U0 was linked to U1 and removed from the database.
  • U2 - has one identity
    • created on the “guest-users” connection with a unique User ID - (ID3).

When the Secondary Identity of U1 (ID2) is linked to U2, it creates linked identities under U2. When linking to an already Linked Identity, there is actually linking to a Linked User (it has at least a Primary and Secondary Identity) and all of their Linked Identities - in this case, U1 with ID1 and ID2. The old Linked User (U1) is then removed, as was done during the original linking of U0 to U1.

U2 - now has three accounts linked

  • A Primary Identity on the “guest-users” connection with User ID: ID3
  • A Secondary Identity on the “guest-users” connection with User ID: ID1
  • A Tertiary Identity on the “sms” connection with User ID: ID2

Solution

In this case, if trying to move the Secondary Identity (ID2) from User 1 to User 2, there should be an unlinked ID2 from U1.

This would create a new User - U4 - which does not have any metadata but does have the Connection User ID (ID2) - and the original U1 without ID2. See the notes under “How it Works”.

Then, link U4 into U2 so that ID3 is the Primary and ID2 is the Secondary.

This would end up looking like:

  • U1 - now has one identity
    • An Identity created on the “guest-users” connection with a unique User ID - (ID1) - which is the same as pre-linked U1
  • U2 - now has two Identities linked
    • A Primary ID is created on the “guest-users” connection with a unique User ID - (ID3).
    • A Secondary identity on the “sms” connection with a unique User ID - (ID2) - formerly U4. U4 has now been linked to U2 and removed from the database.

Now, it is still possible to unlink ID1 from U2, but any metadata that was in U1 before it was linked to U2 needs to be recreated.