DEV Community

Robertino
Robertino

Posted on • Originally published at auth0.com

Migrating Auth0 Hooks to Auth0 Actions

Learn some guidelines to migrate your Auth0 Hooks to Auth0 Actions successfully.


Auth0 Hooks completes the customization capability of Rules in the Auth0 platform. However, Auth0 Actions provide a unified and powerful environment to perform the same tasks you can do with both Rules and Hooks. Learn how to migrate your existing Auth0 Hooks into Auth0 Actions with this article.

Auth0 Actions and Customization

One of the most compelling Auth0 features is its support for customization. Beyond the basic login and logout functionality for your applications, you can tweak the standard flow of some of Auth0's behind-the-scenes processes to meet your specific needs. For example, you can do extra authentication checks or perform specific operations after a user registers with your application.

The features that many Auth0 customers are familiar with to make those customizations are Auth0 Rules and Auth0 Hooks. Auth0 Rules allow you to customize the authentication flow, while Auth0 Hooks enable you to customize the Auth0 behavior for some extensibility points, such as pre and post user registration, password change, phone message sending, and so on.

Now you have Auth0 Actions, an Auth0 feature that allows you to achieve the same customization goals as Rules and Hooks. Auth0 Actions provide you with a unified development environment to customize the extensibility points you were used to doing with Rules and Hooks. Actions not only offer you the same power as Rules and Hooks. They also give you some additional features that simplify your development experience:

  • Actions provide you with an integrated version system. You can modify an Action without affecting the one in production, create multiple versions, and restore a previous one.
  • The Actions editor supports code hints, all npm packages, and isolated secrets management.
  • You can take advantage of a growing number of no-code Actions integrations from the Auth0 Marketplace, which solve common identity use cases such as consent management, progressive profiling, and user verification. Built by Partners, those integrations enable developers to go-to-market faster while reducing development and maintenance costs associated with custom code.

Read this blog post for a quick introduction to Auth0 Actions.

While Auth0 Actions bring you an improved customization environment, Rules and Hooks are still available, and they all can live together. Remember that Rules and Hooks execute before Actions.

Auth0 Actions are a recommended alternative to Auth0 Rules and Hooks. If you customized Auth0 flows with Rules and Hooks and now want to migrate to Auth0 Actions, you are in the right place.

This article provides some guidelines for migrating your Auth0 Hooks to Auth0 Actions. Check out this article to migrate your Auth0 Rules to Auth0 Actions.

Code Conversion Guidelines

To convert your Auth0 Hooks into an equivalent Auth0 Action, follow the guidelines in this section.

This article assumes that you have a basic understanding of how to create a Hook and how to create an Action. If not, please refer to Auth0 documentation about Hooks creation and Actions writing. In both cases, you need an Auth0 account. If you don't have it, you can get one for free.

Mapping Hook types to Action Triggers

The first thing you need to do is identify the Action Trigger that corresponds to your Hook type. Auth0 Action Triggers are events that happen within Auth0 flows. The following table maps each Hook type to the respective Action Trigger:

Hook type Action Trigger
Pre-User Registration Pre User Registration
Post-User Registration Post User Registration
Post-Change Password Post Change Password
Send Phone Message Send Phone Message
Client Credential Exchange M2M/Client-Credentials

The names for Hook types and Action Triggers are almost identical. So, when you are going to convert your Hook into an Action, you need to create the Action by selecting the right Trigger from the list, as shown in the following picture:

Auth0 Action Trigger list

When you select a Trigger, you get an empty named export in the Action editor. The name of the specific export depends on the selected Trigger. For example, if you convert your Post-User Registration Hook into a Post User Registration Action Trigger, you will get the following code in your Action editor:

exports.onExecutePostUserRegistration = async (event) => {

};
Enter fullscreen mode Exit fullscreen mode

You can see this mapping between your Hook type and the corresponding export name in the following table:

Hook type Action Trigger Action named export
Pre-User Registration Pre User Registration `onExecutePreUserRegistration`
Post-User Registration Post User Registration `onExecutePostUserRegistration`
Post-Change Password Post Change Password `onExecutePostChangePassword`
Send Phone Message Send Phone Message `onExecuteSendPhoneMessage`
Client Credential Exchange M2M/Client-Credentials `onExecuteCredentialsExchange`

The body of your Hook will go into the body of your newly created Action, with some changes as you will learn as you go along.

Read more...

Top comments (0)