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

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?

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

This will involve using the Management API to search for the user’s 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:

And on caching tokens in Actions:

Hope this helps!

1 Like

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

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

1 Like

Great! Thanks for sharing with the community :slight_smile:

1 Like

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