Detecting User Migration from Custom Database with Import Mode Enabled
This article clarifies how to determine if a user has migrated from a custom database connection that has Import Mode enabled. It explains why standard user searches are insufficient for this purpose and provides an alternative method for tracking migration status.
-
Custom Database
-
Import Mode
When using a custom database in legacy mode, Auth0 creates a user record in the internal database even if the user has not migrated. Consequently, a user search returns a record for both migrated and non-migrated users, making it impossible to determine migration status through search alone.
To track migration status, add a metadata flag to the user in the custom database login script. After the first login on the new connection with Import Mode enabled, the system no longer calls the login script for that user.
-
Modify the custom database login script to include a flag in
app_metadatathat marks the user as migrated.
//Example of including app_metadata to indication migration occurred
//update app_metadata to include a lazy migration flag
app_metadata: {
lazyMigration: true,
lazyMigrationTime: new Date().getTime()
}
2. Use this metadata flag to identify users who have successfully migrated.