Skip to main content

Get Started

Use the quickstart to write an Action Module and use it from an Action to send logs to an external service.
1

Create an Action Module

To use an Action Module from a specific Action, you first need to create the Action Module and then add/use it in an Action.
  1. Navigate to Auth0 Dashboard > Actions > Library then select Modules.
  2. Select Create Module.
  3. Enter a Name.
  4. Select Create.
Auth0 displays the Code Editor
Actions Modules - New Action Module
2

Add a Secret

Each Action Module can contain secret key/values pairs. Use these to hold sensitive information, such as API Keys, certificates, and values that may change across environments.
Let’s store the external service URL as a Secret.
  1. Select the icon from the code editor’s left sidebar.
  2. Select Add Secret.
  3. Enter the Name as SERVICE_URL.
  4. Enter the external service URL at the Value field.
  5. Select Create.
Actions Modules - Secret added
Auth0 adds the Secret to the Action Module Secret list.
Extra Step: Repeat the steps to store an API_KEY as a Secret that you will send in the headers to the external service in each request.
Once you create a Secret, Auth0 never reveals its value. Auth0 encrypts all Secrets and stores them securely.
Each Action Module Secret is independent from other Actions Modules and Actions Secrets.
Use Secrets at the Action Module by typing actions.secrets.[secret_key].
3

Add Custom Logic

Now, add the following code to your Action Module.
Add the following code to your Action Module:
module.exports = {
  sendLog: async (code, message) => {
    try {
      await fetch(actions.secrets.SERVICE_URL, {
        method: 'POST',
        headers: {
          'X-API-Key': actions.secrets.API_KEY,
        },
        body: JSON.stringify({
          code,
          message
        }),
      });

      console.log({
        code,
        message
      });
    } catch (err) {
      throw new Error('External service failure');
    }

    return;
  }
};
4

Save the Draft

You can save a draft of your Action Module.
  1. Select Save Draft.
Actions Modules - Draft saved
This saves your Action Module without publishing a new version, so it does not affect Actions using it.
5

Publish the Action Module

Once you are satisfied with the Action Module code, it’s time to Publish it.
  1. Select Publish.
Publishing an Action Module takes a snapshot of it at that time and records it as an Action Module Version.
  1. Select View Version History.
Actions Modules - Version History
Auth0 displays the list of Action Module Versions including the draft.
You are now able to start using the Action Module in an Action.
Each Action must explicitly reference the Action Module Version, preventing automatic upgrades that could introduce unexpected errors.
6

Add the Action Module in an Action

Let’s add the Action Module in an Action.
  1. Navigate to Auth0 Dashboard > Actions > Library then select a specific Action.
  2. Once at the Action Editor, select the icon from the left sidebar.
  3. Select Add Module.
  4. Select a Module Name and Version.
  5. Select Add.
Actions - Add Action Module
7

Use the Action Module in the Action

Now, let’s use the Action Module in the Action.
  1. Add the require statement.
const logger = require('actions:logger');
The require statement references the Action Module with the format actions:[module-name].
  1. Add the call to logger.sendLog in the Action function, where you want to send logs.
await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
  1. Select Deploy the Action.
Actions - Use Action Module
Remember to bind the Action to a Trigger.
CheckpointYou should now have a fully functional Action Module being used by an Action.

Advanced Usage

Each Action Module can add/use NPM Dependencies.
  1. Select the icon from the code editor’s left sidebar.
  2. Select Add Dependency.
  3. Enter the Name of the NPM package.
  4. Enter the Version of the NPM package.
  5. Select Create.
Actions Modules - Dependency added
Auth0 adds the Dependency to the Action Module Dependency list.
Use the listed Dependencies at the Action Module by requiring them through require('[package-name]').
When you save this Action, Auth0 resolves the latest version of your dependency and replaces it with a specific version number to keep future updates to the package from breaking your Action.You can provide a specific version instead of latest.