September 28, 2016

Merging Auth0 Accounts

Auth0’s rules engine is extremely powerful and provides many code examples right out of the box. The have a GitHub repository with many examples. One of the examples is a common use case called, link accounts with same email address. What this rule does is ensure that a login with a certain email, as long as it is verified, is combined into the same account with a matching email address. This allows management of a single user that uses multiple social media logins.

The problem that may arise for some is that it merges the existing account with the currently logged in account. That forces a new Auth0 user id in mores cases because this rule really only executes if this is the first login of the logged in account. We found we could reverse the order so that the existing user ids are maintained. Check out the code below.