Can we call an external api to our app from pre-user-registration Action?

I would like to connect to our local db during signup to determine if a user’s email already exists in our db table. I wrote a Pre-User-Registration Action to use an api to execute a function in our application to query our table for the email. I am using axios. Here is the code:

const axios = require(“axios”);

exports.onExecutePreUserRegistration = async (event, api) => {
console.log("email: "+event.user.email);
const url = “https:///find_user”;
const options = {
headers: { “content-type”: “application/json” }
};
const data = {
email: event.user.email
};
console.log(“oose1”);
var user_exists = await axios.get(url, data, options);
console.log(“oose2”);
console.log(“user_exists:”+user_exists);
if(user_exists == true) {
const userMessage = “There already is a user with the provided email in the Storefront_User table.”;
api.access.deny(‘duplicate_email_in_remote_table’,userMessage);
console.log(“is not unique in storefront_user table”);
}
};

Output from Test Results:

Error:
{
  "code": 500,
  "details": "Error: Script execution time exceeded",
  "error": "Script generated an unhandled asynchronous exception.",
  "message": "Script execution time exceeded",
  "name": "Error"
}
Stats:
{
  "total_request_duration_ms": 9820,
  "total_runtime_execution_duration_ms": 9816,
  "runtime_processing_duration_ms": 6,
  "action_duration_ms": 9734,
  "runtime_external_call_duration_ms": 76,
  "boot_duration_ms": 82,
  "network_duration_ms": 4
}

When testing, it always times out. My best guess is that the api is never executed. I know the url works because I put it in the address and it returns true/false. I have a logging call in the function and it is never reached when the action is tested. Am I trying to do the impossible? Most of the examples are referring to calls to Auth0’s apis. Any advice or suggestions?

Thank you.

p.s. By the way, none of the tags provided to choose from include action??!?

After more research, I am wondering if it is a CORS issue? The target url is an api on the AWS (not lambda, just servers). Is this the issue? Is this an axios issue or auth0 issue? Does this mean we are unable to use axios/actions to do a quick lookup of our own db tables during pre-user registration?

I believe I figured out the issue. Since this is a development environment, I was having the action access a url that is inaccessible outside of the firewalls. :woman_facepalming:

1 Like

Hi @chris.howell,

I’m glad you were able to figure out the issue, which involved an inaccessible URL outside of your company’s firewalls.

Let us know if there’s anything else we can help you with.

Thanks,
Rueben

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