# Error at login while migrating users from okta to Auth0

**URL:** <https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344>\
**Category:** Get Help\
**Tags:** user-import-export, user-management\
**Created:** [August 10, 2023, 12:01pm UTC](https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344 "2023-08-10T12:01:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aafreen\_Khan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/aafreen_khan/32/49981_2.png) [@Aafreen\_Khan](https://community.auth0.com/u/Aafreen_Khan)\
**Post date:** [August 10, 2023, 12:01pm UTC](https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344/1 "2023-08-10T12:01:29Z")

</div>

Hello,

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**

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

  request({
    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 : 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
      });
  });
}

```

 ![Migration login error](https://global.discourse-cdn.com/auth0/original/3X/3/1/31fe611fbef837fedaf790d1715b82d46455c6be.png)

Thanks in advance  
Aafreen

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 14, 2023, 3:29pm UTC](https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344/3 "2023-08-14T15:29:07Z")

</div>

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](https://auth0.com/docs/authenticate/database-connections/custom-db/templates/login#callback-function)

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

---

<div class="post-metadata">

**Author:** ![Aafreen\_Khan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/aafreen_khan/32/49981_2.png) [@Aafreen\_Khan](https://community.auth0.com/u/Aafreen_Khan)\
**Post date:** [August 25, 2023, 12:13pm UTC](https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344/4 "2023-08-25T12:13:46Z")

</div>

Hi Dan,

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

Regards,  
Aafreen Khan

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 25, 2023, 12:55pm UTC](https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344/5 "2023-08-25T12:55:16Z")

</div>

Great, let us know if you have any questions.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 8, 2023, 12:56pm UTC](https://community.auth0.com/t/error-at-login-while-migrating-users-from-okta-to-auth0/113344/6 "2023-09-08T12:56:13Z")

</div>

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