User export: Include Applications Through Which the User has Authenticated

Problem statement

When exporting users via the user import/export extension, is there a way to include the names of applications users have logged into?

Solution

There is no field in the user profile that lists the names of applications the user has logged into.

One solution is to create a login action that will update an app_metadata field with the application name the user has logged into, e.g.:

exports.onExecutePostLogin = async (event, api) => {
  const existingApplications = event.user.app_metadata.applications || [];
  const currentApplication = event.client.name;

  if(!existingApplications.includes(currentApplication)) {
    existingApplications.push(currentApplication);
    api.user.setAppMetadata('applications', existingApplications);
  }
}

When a user logs in, if the app_metadata.applications array is non-existent or does not include the current application name, it will be updated to include the existing application name.