Managing Trial Periods with Auth0 Actions
Tags: webdev, programming, tutorial
Published: 2022-01-27 19:01:00

### How to use Auth0 Actions to let users access your application or website for a trial period.


### <br>

Assume you want to let users try your application's services for a given period of time, say 30 days. How can you let users register and then block them after the trial period expires? You can easily leverage Auth0 Actions to achieve this result.

## Setting Up the Sample App

To show you how to enable a trial period for your application, this article will be referring to a sample web application that allows the user to access a fictitious online catalog.

> The sample application you are going to use in this article is built with C# and requires [.NET](https://dotnet.microsoft.com/en-us/download) installed on your machine. <u>However, the user registration customization you will implement is independent of your application's specific programming language and framework.</u>

You can download the sample application by cloning its GitHub repository with the following command:

```bash
git clone https://github.com/auth0-blog/acme-aspnet-mvc.git
```

Once you download it, take a look at the [README file](https://github.com/auth0-blog/acme-aspnet-mvc/blob/main/README.md) and follow its instructions to configure the application to use Auth0. You need an Auth0 account, and if you don't yet have it, you can <a href="https://auth0.com/signup" data-amp-replace="CLIENT_ID" data-amp-addparams="anonId=CLIENT_ID(cid-scope-cookie-fallback-name)">sign up for a free one</a>.

> If you want to learn the details of the sample application implementation, [this blog post describes how it has been integrated with the Auth0 authentication services](https://auth0.com/blog/add-authentication-aspnet-core-mvc/).

After configuring the sample application, you can run it with the following command:

```bash
dotnet run
```

Now, head your browser to the [https://localhost:7095/](https://localhost:7095/) address, you should get the following page:

![Sample app home page](https://images.ctfassets.net/23aumh6u8s0i/5yO9ER9JsSrsFGXj5e1w6e/3c4f71b3286b43249d0e89a3e7e44c70/acme-homepage-login.png)

## Auth0 Actions and Flows

Once you have ensured that your application is properly configured and running, let's briefly explore Auth0's features that will allow you to implement the trial period: Auth0 Actions and Flows.

[Auth0 Actions](https://auth0.com/docs/actions) are JavaScript functions running in a Node.js environment executed when specific events happen in a few internal Auth0 Flows.

[Auth0 Flows](https://auth0.com/docs/actions/triggers) are the processes that can be extended with Actions. Each Flow is made up of one or more triggers and represents the logical pipeline through which information moves during a single point in the Auth0 journey.

For example, you can consider the Login Flow, which runs when a user logs in. This Flow has a post-login trigger: an event fired after the user logs in. You can handle this event through one or more Actions. In other words, you can see Actions as event handlers that run when a specific event fires in an Auth0 Flow.

The following is a graphical representation of an Action (*AddRoles*) that will be executed in the Login Flow after the user logs in:

![Auth0 Action in the Login Flow](https://images.ctfassets.net/23aumh6u8s0i/1pJn7J2p7cICewJkSv4Ecj/4030cd2fa04c3df43e8c29b3c537b68c/auth0-action-in-login-flow.png)

The following are the available Auth0 Flows you can customize with Actions:

- *Login*, running when a user logs in.
- *Pre User Registration*, running before a user is added to the users' store.
- *Post User Registration*, running after a user is added to the users' store.
- *Post Change Password*, running after the user changes their password.
- *Send Phone Message*, running when you configure a custom [Multi-Factor Authentication (MFA)](https://auth0.com/docs/login/mfa) provider.
- *Machine To Machine*, running when an access token is issued to a client using the [Client Credential Flow](https://auth0.com/docs/authorization/flows/client-credentials-flow).

You will use a couple of these Flows to implement the trial period feature for the sample application.

To learn more about Actions, you can check out these blog posts for [a quick introduction to Auth0 Actions](https://auth0.com/blog/introducing-auth0-actions/) and how they [compare with the deprecated Rules and Hooks](https://auth0.com/blog/actions-now-generally-available/).


[Read more...](https://auth0.com/blog/managing-trial-periods-with-auth0-actions/?utm_source=content_synd&utm_medium=sc&utm_campaign=actions)