Amount of users Auto imported from Custom Database Connection

We are migrating the users from a Firebase source, we set up a custom database connection, and some months later we enabled auto import, we have users who already logged in after the auto import was enabled and some that still do not have the password imported from Firebase. How can we know the amount of users that have already been fully migrated to Auth0?

Hi @henrique.rotava.n,

Welcome to the Auth0 Community!

You can find the users that have already been fully migrated to Auth0 by going to your Dashboard > User Management > Users and searching by Connection.

On that page, you can pass in identities.connection:"Your-Custom-Database-Connection-Name" in the search field to filter for users in your custom database.

Alternatively, you can use the User Import / Export Extension to export your users from your custom database connection.

This will provide you with a file of your exported users that you can download. Then, you can use this information to cross-check your Firebase source to verify which users have not yet migrated.

Let me know if you have any questions.

Thanks,
Rueben

Hi @rueben.tiow ,

The thing is that even if the user is already imported to my custom connection, the “Import Users to Auth0” could be off at the time, once I turn it on the password hash would be persisted to Auth0 accordingly to the following diagram:

Based on this flow Import and Export Users

How do I know the password is also imported to Auth0 for those users?

Hi @henrique.rotava.n,

Thanks for your update.

You could add a flag to the user’s user_metadata to indicate that they have migrated in your Login database action script.

For example, here’s a sample script:

function login(email, password, callback) {
  const bcrypt = require('bcrypt');
  const MongoClient = require('mongodb@3.1.4').MongoClient;
  const client = new MongoClient('mongodb://user:pass@localhost');

  client.connect(function (err) {
    if (err) return callback(err);

    const db = client.db('db-name');
    const users = db.collection('users');

    users.findOne({ email: email }, function (err, user) {
      if (err || !user) {
        client.close();
        return callback(err || new WrongUsernameOrPasswordError(email));
      }

      bcrypt.compare(password, user.password, function (err, isValid) {
        client.close();

        if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));

        return callback(null, {
            user_id: user._id.toString(),
            nickname: user.nickname,
            email: user.email,
            user_metadata: { migrated: true }
          });
      });
    });
  });
}

This way, you can query for the list of users in your custom database connection and filter to find which users have the migrated flag. If the user logs in at least once since you turned on the “Import users to Auth0” feature, they will have the migrated flag. Users without the migrated flag will mean that they have not yet migrated their passwords.

(Reference: Verify user migration is complete)

I hope that helps!

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.