Maybe I wasn’t clear about that, but the API can return whatever you want as long as the script returns the expected contract. I.e. this is fine:
function getUser(email, callback) {
request.get("https://yourAPI/users/" + email, function(err, res, body) {
if (err) {
callback(err);
}
if (res.statusCode === 404) {
// convert the 404 response from the API into
// a null profile, to signal that the user doesn't exist
return callback(null, null);
}
var profile = {
user_id: body.id,
[...]
};
callback(null, profile);
});
}
My desired outcome is both lazy migration and bulk migration. Is this possible using the same connection? I tried using two connections but you still have to specify which connection to use when logging in.
Generally, you’d want only one connection, unless you are looking to isolate different sets of users for some very good reason.
It sounds as if what you are looking for could be a custom DB with import mode on (i.e. lazy migration) and, when you have a set of users that you want to import, you can do so into that same connection
(using the bulk import feature).
When a user tries to log in Auth0 will look internally first. If not found, it will try the login script.
When you try to create a user, Auth0 will also look internally, and if not found it will also use the Get User script to ensure that the user doesn’t already exists in the external DB. The Get User script is also used for other flows, like the forgot password one.
When you create new users, you should do so in Auth0 (after all, you are trying to migrate users to Auth0). If you need some kind of shadow record in an external place, maybe you can use a post-registration hook, or simply insert that record as part of the user sign-up flow. I.e.:
User goes through registration screen → create user in Auth0 → create user somewhere else.
Not sure why you are trying to create the new user in the external DB as well, though. Those two records are likely to be out of sync eventually, unless you are very careful with updates.