How to Check Whether a User Has a Linked Profile

Overview

This article explains how to check whether or not a user has a linked profile in Auth0.

Applies To

  • User Account Linking

Solution

To check whether a user has a linked profile or not, count the number of elements in the identities array in a user object.

Step 1: Get users

  1. Install the User Import/Export Extension

  2. Go to the left menu: Extension > Export

    • Click ADD DEFAULT FIELDS
      • Add the following field
        • User Field: identities
        • Column Name: identities
    • In the SETTINGS section, select:
      • Export Format: JSON file (*.json)
      • Connection: All connections
    • Click EXPORT X USERS

Note: The User Import / Export Extension is intended to be used to export Database Connection users. However, users associated with other types of connections (e.g., Social) can also be exported when choosing “All connections” for Connection.

Step 2: Check the length of the identities array in each user object.

If the identities array has only one element, the user does not have a linked profile.

Example:

{
  "Id": "facebook|33333",
  "Email": "primary@example.com",
  "Email Verified": true,
  "Connection": "facebook",
  "identities": [
    {
      "profileData": {
        "email": "primary@example.com",
        "email_verified": true
      },
      "user_id": "33333",
      "provider": "facebook",
      "connection": "facebook",
      "isSocial": true
    }
  ]
}

If the identities array has two or more elements, the user has a linked profile.

{
  "Id": "google-oauth2|11111",
  "Email": "primary@example.com",
  "Email Verified": true,
  "Connection": "google-oauth2",
  "identities": [
    {
      "profileData": {
        "email": "primary@example.com",
        "email_verified": true,
      },
      "provider": "google-oauth2",
      "user_id": "11111",
      "connection": "google-oauth2",
      "isSocial": true
    },
    {
      "profileData": {
        "email": "secondary@example.com",
        "email_verified": false
      },
      "connection": "Username-Password-Authentication",
      "user_id": "22222",
      "provider": "auth0",
      "isSocial": false
    }
  ]
}

Related Reference:

1 Like