Angular 1.x Rules

Sample Project

Download this sample project configured with your Auth0 API Keys.

Rules are one of the most powerful features of Auth0. As JavaScript functions that execute each time a user authenticates, rules serve as middleware to extend the flexibility of your authentication flow. For a detailed description of rules, see the full documentation.

Create a Rule

To create a rule, go to the New Rule page. You can create a rule from scratch by selecting an empty rule, or you may use one of the existing templates. These templates are written by Auth0 to cover common scenarios and use cases.

For this example, select the Add country to the user profile rule.

Empty rule

This rule extracts the country_name from the context and adds it to the user profile as a new country attribute.

Add country rule

Note: You can use any of the pre-built rules or create your own to meet your business needs.

Once complete, click Save. The rule will execute any time a user logs in, and the country will be added to the user's profile.

Test the Rule

To see the results of a created rule, log in and fetch the user’s profile information, as explained in the User Profile step.

Then you can display the user profile's new country attribute added by the rule:

<!-- components/home/home.html -->

<div class="text-center" ng-if="isAuthenticated">
  <h2>Welcome, {{ vm.profile.nickname }},</h2>
  <h3 ng-if="vm.profile.country">from {{ vm.profile.country }} <span class="additional-info">(added by rule)</span> </h3>
  <img ng-src="{{ vm.profile.picture }}">
</div>

Country rule sample

Previous Tutorial
6. Linking Accounts
Next Tutorial
8. Authorization
Use Auth0 for FREECreate free Account