Ionic Rules

Download a sample project.

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 use one of the existing templates. These templates are written by Auth0 to assist you to in executing common tasks.

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

This is just the beginning, you can edit the rule 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, login and fetch user profile information as explained in the User Profile step.

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

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

<ion-view view-title="Auth0 Ionic Quickstart" ng-controller="HomeController as vm">
  <ion-content class="padding">
    <div ng-hide="isAuthenticated">
      <p>Welcome to the Auth0 Ionic Sample! Please log in:</p>
      <button class="button button-full button-positive" ng-click="vm.login()">
        Log In
    <div ng-show="isAuthenticated">
      <div class="list card">
        <div class="item item-avatar">
          <img src="{{ vm.profile.picture }}">
          <h2>{{ }}</h2>
          <span ng-if="" class="additional-info">Country (added by rule): <strong>{{ }}</strong></span>
        <a class="item item-icon-left assertive" ng-click="vm.logout()">
          <i class="icon ion-log-out"></i> Log Out

Mobile example screenshot
Previous Tutorial
5. Linking Accounts
Next Tutorial
7. Authorization
Try Auth0 for FREECreate free Account