Use this file to discover all available pages before exploring further.
Auth0 supports the linking of user accounts from various . You can use server-side code to link accounts on a regular web application, engaging the user and asking them for permission before proceeding. Your code will authenticate users and search for and identify users using their email addresses. Your application will then prompt the user to link their accounts by authenticating with the target account’s credentials, and later link the accounts.You can find the full source of this sample application on GitHub.
Log the user into your application. The user authenticates to your application using Universal Login. To learn more, read the Regular Web App Quickstart, asking for a token for the Auth0 Management API audience (audience=https://{yourDomain}/api/v2/).
Search for users with identical email addresses. You can get the user profile and the list of users with the same verified email.
If Auth0 returns one or more records with matching email addresses, the user will see the list along with the following message prompting them to link the accounts.
If the user wants to link a given account, they can click Link next to the appropriate account.
When the user clicks Link, your application will ask the user to authenticate with the target account, and then perform account linking.
To retain and merge the user_metadata from the secondary account, you must retrieve and merge it into the metadata for the primary account before calling the API endpoint. After the accounts are linked, the metadata for the secondary account is discarded.When you initiate account linking, you can select which identity will be used as the primary account and which as the secondary. This choice will depend on which set of attributes you want to retain in the primary profile.
The following code snippet shows how to verify and merge metadata:
The following example shows explicitly how the user_metadata and app_metadata from the secondary account gets merged into the primary account using the Node.js Auth0 SDK for API V2.
/* * Recursively merges user_metadata and app_metadata from secondary into primary user. * Data of primary user takes preponderance. * Array fields are joined. */async function mergeMetadata(primaryUserId, secondaryUserId) { // load both users with metedata. const [primaryUser, secondaryUser] = await Promise.all( [primaryUserId, secondaryUserId].map((uid) => auth0Client.getUser(uid)) ); const customizerCallback = function (objectValue, sourceValue) { if (_.isArray(objectValue)) { return sourceValue.concat(objectValue); } }; const mergedUserMetadata = _.merge( {}, secondaryUser.user_metadata, primaryUser.user_metadata, customizerCallback ); const mergedAppMetadata = _.merge( {}, secondaryUser.app_metadata, primaryUser.app_metadata, customizerCallback ); await auth0Client.updateUser(primaryUserId, { user_metadata: mergedUserMetadata, app_metadata: mergedAppMetadata, });}