Use the
@auth0/actions NPM package to write and unit test your Actions in your own code editor or IDE, with full IntelliSense, type checking, and error checking.
Install the package
Use one of the following package managers to install the package:
- NPM
- Yarn
- Pnpm
Use
--save-dev while installing the package to indicate that it’s a development dependency to supplement your development tools.Import the type definitions
Use one of the following alternatives to import the TypeScript definitions into your Actions depending on your technology:
- JSDocs @import
- JSDocs @param
- TS types import
Use this alternative when you want IntelliSense without changing your existing JavaScript code structure:
The import statement should be based on each trigger name and version number considering the library structure.Follow the pattern:
@auth0/actions/[trigger_name]/[trigger_version]For example: @auth0/actions/post-login/v3Library structure
Library structure
Configure your project
The following configuration examples are intentionally presented in both JavaScript and TypeScript to provide a direct, side-by-side comparison.
- JavaScript
- TypeScript
In your
package.json, define any development dependencies to have intelliSense help when writing your Action:Write your Action code
The following example Action would execute during the Post-Login flow. It checks if the user has roles assigned, and calls
api.access.deny() if none are found. If roles are present, it proceeds to set the custom claim on the ID token.The import statement declares the availability of external types to your code. This allows the editor to know the structure of the event and api objects.- JavaScript
- TypeScript
CheckpointYou should now have a working Action, written and type-checked in your own code editor, ready to be deployed to Auth0.