@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.install-npm.sh
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:
jsdocs-import.js
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
@auth0/actions
credentials-exchange
v1
v2
custom-email-provider
v1
custom-phone-provider
v1
custom-token-exchange
v1
event-stream
v1
password-reset-post-challenge
v1
post-change-password
v1
v2
post-login
v1
v2
v3
post-user-registration
v1
v2
pre-user-registration
v1
v2
send-phone-message
v1
v2
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 In your
package.json, define any development dependencies to have intelliSense help when writing your Action:package.json
jsconfig.json, define any development dependencies to have intelliSense help when writing your Action.jsconfig.json
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
example.js
CheckpointYou should now have a working Action, written and type-checked in your own code editor, ready to be deployed to Auth0.