iOS-Swift Rules

Sample Project

Download this sample project configured with your Auth0 API Keys.

System Requirements
  • CocoaPods 1.0.0
  • XCode 7.3 (7D175)
  • iPhone 6 - iOS 9.3 (13E230)
Show requirements

Rules are functions written in JavaScript that are executed in Auth0 as part of the transaction every time a user authenticates to your application. For more information about Auth0 rules, please refer to the full documentation.

Create a Rule

To create a rule, just go to the new rule page. You can create it from scratch or use an existing template. These templates are written by Auth0 team to assist you complete common tasks.

Let's use the template called "Add country to the user profile", under the Enrich Profile section:

Add country template

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

Country rule sample

This is just a starting template, you can edit it to meet your business needs. Once you are done, save the rule and that's it. Whenever you login, the rule will be executed, and the country will be added.

Test the Rule

To see the created rule results, just implement a login and fetch the user profile information (you can check out how to do it in the login tutorial).

You can access the country added by the rule within the extraInfo dictionary from the A0UserProfile object, like so:

import Lock
let profile: A0UserProfile = ... // the user profile you get upon login
guard let country = profile.extraInfo["country"] as? String else {
    // test failed
print("user country is: \(country)")
Previous Tutorial
6. Linking Accounts
Next Tutorial
8. Authorization
Use Auth0 for FREECreate free Account