Skip to main content

Usage

Database action scripts are Node.js functions that you write for custom database connections. They define how Auth0 interfaces with your external user store during functionality like logins, password changes, and user deletion. Database action scripts execute as a series of called JavaScript functions in an instance of a serverless Webtask container.

Completion and the callback function

The function signature for each database action script includes a callback function as its final parameter. Auth0 supplies this callback function, which signals completion of operation. Every database action script must call its callback function exactly once, immediately before it completes (either implicitly or explicitly with a return statement). Failure to execute the callback function results in a stall of execution and ultimately returns an error. For troubleshooting, you can use return errors from your database action scripts by passing an Error object to the callback function:
Calling the callback function with no parameters, as in callback(), is equivalent to calling it with callback(null).

Asynchronous JavaScript

Database action scripts support asynchronous JavaScript features, including Promise objects and async functions. You can use asynchronous features to execute non-blocking operations from an action script. If your action script uses asynchronous processing, you must defer the call to the callback function until asynchronous processing completes. Asynchronous operations must complete within the execution limit of the Webtask container.

Public npm modules

npm modules reduce the overall size of action scripts and provide access to a wide range of pre-built functionality. Auth0 serverless Webtask containers can use many supported public npm modules. If you require another module, make a request with your Auth0 representative or open a support ticket. Action scripts do not support npm modules from private repositories.

Provided artifacts

We provide a specific environment with a number of artifacts supplied by both the Webtask container and the Auth0 (your Auth0 tenant) itself.

global object

Auth0 serverless Webtask containers are provisioned from a pool associated with each Auth0 tenant. All action scripts that execute within a container instance can access the global object, which acts as a global variable unique to the container. You can use the global object to define information or functions used across all action scripts that run in the container instance or cache expensive resources, like storing an for a third-party (logging) API or your own API defined in Auth0 and obtained via the Client Credentials Flow.
Do not store user-specific information the global object. Because there is no container affinity for action script execution in Auth0, action scripts may execute in any running container instance or in a new container instance added to the pool.
All assignment declarations in the global object should also include provision for initialization because the global object is reset when a Webtask container is recycled or instantiated.

configuration object

You can set configuration parameters in database action scripts to make values available to all scripts through the configuration object. Values are encrypted. Treat the configuration object as read-only and use it to avoid hard-coding values in your action scripts. For example, you can store sensitive information such as credentials or API keys for accessing external identity stores or define variables with tenant-specific values.

context object

If you use Organizations, you can make Organization data available to your database action scripts by enabling the context object. This passes an additional context argument to custom database scripts containing Organization details like id, name, and metadata. You cannot disable the context object after you enable it. The Delete script is always passed an empty context object.

Limits

  • The total size of an action script must not exceed 100 KB, excluding imported npm modules. Larger sizes introduce more latency due to the Webtask platform’s packaging and transport process, which impacts the performance of the system.
  • Each action script’s Webtask container has an execution limit of approximately 20 seconds after which the container is recycled. This terminates the action script’s pending operations and may result in errors.