Error at login while migrating users from okta to Auth0


I am Migrating users from Okta to Auth0 following the steps in Auth0 docs.

However, after setting up the login and get user script i am getting an error when trying to login after clicking on “Try Connection”.Attached is the screenshot of the error page and the Login Script i used.

On the logs i can see the error description as “error unhandled”

Can anyone please suggest anything?

Login Script

function login (email, password, callback) {
  var url = 'https:/{my_okta_tenant}/api/v1/authn';

    url: url,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    body: {
      username: email,
      password: password,
      options: {
        multiOptionalFactorEnroll: false,
        warnBeforePasswordExpired: false
    json: true
  }, function (error, response, body) {
    // Ensure we have a successful response
    if (response.statusCode !== 200) return callback();

    // Get the user from the response body
    var user = body._embedded.user;

    // Set the data we want to store in Auth0 and migrate the user
    return callback(null, {
        user_id :,
        username: user.profile.login,
        email: user.profile.login,
        // We set the users email_verified to true as we assume if they were a valid
        // user in Okta, they have already verified their email
        // If this field is not set, the user will get an email asking them to verify
        // their account
        email_verified: true,
        name: user.profile.firstName + ' ' + user.profile.lastName

Thanks in advance

Hi @Aafreen_Khan,

Make sure you have some logic to handle errors in your login script. There’s some examples in this section of the doc: Login Script Templates

Are you seeing any specific errors coming back from your custom database?

Hi Dan,

Thanks for the help.
I will refer this template and add some error logic into it.

Aafreen Khan

1 Like

Great, let us know if you have any questions.

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