Migrating Social Connection Users to Another Auth0 Tenant

Overview

This article describes the process for migrating Social Connection users to a new tenant.

Applies To

  • Social Connection
  • Bulk User Import

Solution

The user data in Social Connections cannot be bulk-imported by design. To generate the identical user record in a new tenant, the user must log in using the same Identity Provider (IdP).

 

This limitation introduces complications when user metadata and application metadata are attached to user records in the previous tenant. To resolve this, store the metadata in an external storage system and restore the data upon login.

 

For example, in a Post-login Action:

exports.onExecutePostLogin = async (event, api) => {
  // A guard clause should be in place to avoid unnecessary external API calls 
  if (event.connection.name === "xxx" && !event.user.app_metadata.migration_complete) {
    const userMetadataSnapshot = (...) // Fetch saved user_metadata from the external storage
    Object.keys(userMetadataSnapshot).forEach(function (key) {
      api.user.setUserMetadata(key, userMetadataSnapshot[key])
    })
    api.user.setAppMetadata("migration_complete", true)
  }
}

 

NOTE:

  • This example is not for production use. The production code may need additional testing, optimization, error handling, and/or security considerations.
  • A guard clause should be in place to avoid unnecessary external API calls.

Recommended content

No recommended content found...