# How do I check if a user exists in a different connection, when in action script?

**URL:** <https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897>\
**Category:** Get Help\
**Tags:** automatic-migration, user-management\
**Created:** [August 17, 2023, 7:27pm UTC](https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897 "2023-08-17T19:27:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![auth0rocks](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth0rocks/32/50004_2.png) [@auth0rocks](https://community.auth0.com/u/auth0rocks)\
**Post date:** [August 17, 2023, 7:27pm UTC](https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897/1 "2023-08-17T19:27:40Z")

</div>

Hi, I want to check if a user with the currently processing email address exists in a different connection in the tenant, when in a post login action script,. The goal here is to grab a piece of info (app\_metadata) from that user if it exists, and copy it over to the user record just created by auth0 in the current connection.

Is this possible?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 18, 2023, 2:16am UTC](https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897/2 "2023-08-18T02:16:07Z")

</div>

Hey there @auth0rocks welcome to the community (sweet username 🙂 )!

> [@auth0rocks](#):
>
> I want to check if a user with the currently processing email address exists in a different connection in the tenant, when in a post login action script,

This will involve using the Management API to [search for the user’s email](https://auth0.com/docs/api/management/v2/users-by-email/get-users-by-email) at which point I believe you’d have the information you need.

Here’s some info on how to use the Management API in Actions:

[https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947)

And on caching tokens in Actions:

[https://community.auth0.com/t/caching-management-api-access-tokens-in-login-action/95855](https://community.auth0.com/t/caching-management-api-access-tokens-in-login-action/95855)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![auth0rocks](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth0rocks/32/50004_2.png) [@auth0rocks](https://community.auth0.com/u/auth0rocks)\
**Post date:** [August 18, 2023, 5:35am UTC](https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897/4 "2023-08-18T05:35:30Z")

</div>

Thanks! Indeed I found a way to do this vai sth like this

```auto
const ManagementClient = require('auth0').ManagementClient;
      const management = new ManagementClient({
          domain: event.secrets.domain,
          clientId: event.secrets.clientId,
          clientSecret: event.secrets.clientSecret,
      });

      const userRecords = await management.getUsersByEmail(event.user.email);

```

thanks

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 18, 2023, 10:50pm UTC](https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897/5 "2023-08-18T22:50:13Z")

</div>

Great! Thanks for sharing with the community 🙂

---

<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 1, 2023, 10:50pm UTC](https://community.auth0.com/t/how-do-i-check-if-a-user-exists-in-a-different-connection-when-in-action-script/113897/6 "2023-09-01T22:50:36Z")

</div>

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