User_id: "auth0|undefined" after signup

I’ve searched plenty without any success. My issue is similar to User id undefined with custom database signup but I could not find the answer there.

I have a custom database that I’'ve configured to “migrate to auth0”. When a user signs up it gets a user_id of “auth0|undefined”. If a second user logs in it also gets the same ID… they share id some how…

The next time that first user logs in, it gets a proper user_id.

I dont understand what Im doing wrong… Any advice would be helpful.

Can you provide the code snippet you use to set the user_id in the custom db login template?

https://auth0.com/docs/connections/database/custom-db/templates/login#javascript

Thank you for the answer.
Sure, here is my login script:

function login (email, password, callback) {
  request.post({
    url:  'https://xxx.com/some/path/login',
    json: {
      email: email,
      password: password
    },
    auth: {
      username: "foobar",
      password: configuration.auth_password
    }
  }, function (err, response, body) {

    if (err) return callback(err);
    if (response.statusCode === 401) return callback();

    callback(null,   {
      user_id:     body.user_id,
      nickname:    body.nickname,
      email:       body.email,
      roles:       body.roles
    });
  });
}

My register script look like this:

function create (user, callback) {
  request.post({
    url:  'https://xxx.com/some/path/create',
    json: user,
    auth: {
      username: "foobar",
      password: configuration.auth_password
    }
  }, function (err, response, body) {

    if (err) return callback(err);
    if (response.statusCode === 401 || response.statusCode === 403) return callback(new Error("Forbidden"));
    if (response.statusCode === 409) return callback(new ValidationError("user_exists", "User exists"));

    callback(null);
  });
}

I see that you ask for my login script. But Im concerned about the registration. Why does my user have user_id: "auth0|undefined" after they registered?